Repository navigation
fix(kafka): Flush producers on exit - #15934
Conversation
We need to make sure the producers are flushed when exiting the application as otherwise we risk losing events that were not yet sent to Kafka, which happened to me with the backfill script.
|
FYI: I'm planning to follow up with replacing the |
tkaemming
left a comment
There was a problem hiding this comment.
I'm +1 on this, but want to make sure somebody else has eyes on it before merging in case they can think of any unwanted side-effects that we have missed.
FYI: I'm planning to follow up with replacing the
SIGINTandSIGTERMhandlers below withatexit.registerand adding a globalSIGINTandSIGTERMhandler torunner/__init__.pythat callssys.exit(0)to ensure triggeringatexitevents with these signals.
These signal handlers should be fine as-is. They just prevent a preemptive KeyboardInterrupt from being thrown in the main loop of the batching consumer, and allow it to shutdown safely after it finishes the work in progress. To my understanding, that should be an orthogonal concern and not interfere with the atexit handlers since the main thread exits normally.
Not really as the registered handler is not always called when |
My argument is the correct place to do this is using the |
I guess I don't really see how this approach would change anything — or even work — but it's possible I'm not really understanding your intention here. Are you trying to ensure the consumer completes its work gracefully before interpreter shutdown? If so, the only way to do that is to wait for the This is the approach suggested by several comments in that SO thread:
If this doesn't address your concerns, maybe it's easier to just make that change and we can talk about the specific change rather than a hypothetical one. |
I think we are talking about different things. All I care about is consolidating code. I'm okay with the current way of breaking the loop.
That is my intention: move away from signal handlers and simply use |
tkaemming
left a comment
There was a problem hiding this comment.
That is my intention: move away from signal handlers and simply use
atexit.registerfor all these things, normalizing it with a globalsigtermhandler.
I don't really understand how this would work, but maybe if I see the implementation it'll make more sense.
Upgrades existing events from last `$SENTRY_EVENT_RETENTION_DAYS` to Snuba automatically. Relies on getsentry/sentry#15934.
Instead of sprinkling incomplete signal handlers over the codebase prefer using `atexit.register` and trigger an exit upon receiving `SIGTERM` as it normally bypasses the `atexit` callbacks. The new code should behave identical to the old one, but more complete as in it now handles more exit triggers instead of just `SIGINT`. This is a follow up to #15934.
Upgrades existing events from last `$SENTRY_EVENT_RETENTION_DAYS` to Snuba automatically. Relies on getsentry/sentry#15934.
) Upgrades existing events from last `$SENTRY_EVENT_RETENTION_DAYS` to Snuba automatically. Relies on getsentry/sentry#15934.
We need to make sure the producers are flushed when exiting the application as otherwise we risk losing events that were not yet sent to Kafka, which happened to me with the backfill script.