Skip to content

fix: eliminate data race on application mode and reason fields#252

Open
Aliexe-code wants to merge 1 commit intoergo-services:masterfrom
Aliexe-code:fix/application-race-condition
Open

fix: eliminate data race on application mode and reason fields#252
Aliexe-code wants to merge 1 commit intoergo-services:masterfrom
Aliexe-code:fix/application-race-condition

Conversation

@Aliexe-code
Copy link
Copy Markdown

@Aliexe-code Aliexe-code commented Feb 20, 2026

Summary

Fixes #246

Eliminates the data race between application.stop() and application.terminate() during node shutdown by using atomic operations for mode and reason fields.

Changes

  • Changed mode field from gen.ApplicationMode to int32 with atomic load/store operations
  • Changed reason field from error to atomic.Value for thread-safe access
  • Fixed race on state field in registerAppRoute() by using atomic load
  • Fixed log ordering in start() to log mode after storing it

Root Cause

The race occurred because:

  1. stop() writes to mode and reason
  2. terminate() reads these fields concurrently when child processes exit
  3. No synchronization existed between these concurrent accesses

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Feb 20, 2026

CLA assistant check
All committers have signed the CLA.

@Aliexe-code Aliexe-code force-pushed the fix/application-race-condition branch from 578f53c to c789421 Compare February 20, 2026 02:04
Fixes ergo-services#246

Changed mode from gen.ApplicationMode to int32 with atomic operations.
Changed reason from error to atomic.Value for thread-safe access.

This fixes the race between stop() and terminate() during shutdown.
Also fixed race on state field in registerAppRoute() by using atomic load.
@Aliexe-code Aliexe-code force-pushed the fix/application-race-condition branch from c789421 to 5aa7518 Compare February 24, 2026 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Data Race in Application Shutdown: stop() vs terminate()

2 participants