Skip to content

fix(plugin-broker): drain pending alerts and wait for in-flight deliveries on shutdown#4488

Open
andreabravetti wants to merge 1 commit into
crowdsecurity:masterfrom
andreabravetti:fix/plugin-broker-shutdown-race
Open

fix(plugin-broker): drain pending alerts and wait for in-flight deliveries on shutdown#4488
andreabravetti wants to merge 1 commit into
crowdsecurity:masterfrom
andreabravetti:fix/plugin-broker-shutdown-race

Conversation

@andreabravetti
Copy link
Copy Markdown

When cscli notifications test kills the plugin tomb immediately after enqueuing an alert, the broker's select loop can pick the Dying() channel before reading PluginChannel, silently dropping the notification. The inner loop after watcher.Kill() also races Dead() vs PluginEvents, losing alerts queued by addProfileAlert.

Fix with a 3-step shutdown sequence:

  1. Drain PluginChannel
  2. Flush alertsByPluginName map
  3. Wait for in-flight delivery goroutines via sync.WaitGroup before Kill()

Also wrap PluginEvents delivery in a goroutine with WaitGroup tracking.

Fixes issue #4487

…eries on shutdown

When cscli notifications test kills the plugin tomb immediately after
enqueuing an alert, the broker's select loop can pick the Dying() channel
before reading PluginChannel, silently dropping the notification. The
inner loop after watcher.Kill() also races Dead() vs PluginEvents,
losing alerts queued by addProfileAlert.

Fix with a 3-step shutdown sequence:
1. Drain PluginChannel
2. Flush alertsByPluginName map
3. Wait for in-flight delivery goroutines via sync.WaitGroup before Kill()

Also wrap PluginEvents delivery in a goroutine with WaitGroup tracking.
@github-actions
Copy link
Copy Markdown

@andreabravetti: There are no 'kind' label on this PR. You need a 'kind' label to generate the release automatically.

  • /kind feature
  • /kind enhancement
  • /kind refactoring
  • /kind fix
  • /kind chore
  • /kind dependencies
Details

I am a bot created to help the crowdsecurity developers manage community feedback and contributions. You can check out my manifest file to understand my behavior and what I can do. If you want to use this for your project, you can check out the BirthdayResearch/oss-governance-bot repository.

@github-actions
Copy link
Copy Markdown

@andreabravetti: There are no area labels on this PR. You can add as many areas as you see fit.

  • /area agent
  • /area local-api
  • /area cscli
  • /area appsec
  • /area security
  • /area configuration
Details

I am a bot created to help the crowdsecurity developers manage community feedback and contributions. You can check out my manifest file to understand my behavior and what I can do. If you want to use this for your project, you can check out the BirthdayResearch/oss-governance-bot repository.

@andreabravetti
Copy link
Copy Markdown
Author

/kind fix

@andreabravetti
Copy link
Copy Markdown
Author

I'm having trouble choosing the right area, perhaps a mix of agent and cscli?
A plugin or notification area might be more suitable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant