Skip to content

Shutdown parity with JS #47: drain on SIGTERM/SIGHUP, unregister atexit #31

Description

@anassg-lago

JS PR getlago/lago-agent-sdk-js#47 fixed two shutdown behaviors the Python port is missing:

  1. Buffered events are lost on SIGTERM and SIGHUP. The queue's only exit hook is atexit.register (queue.py:136), and CPython does not run atexit handlers on SIGTERM's default action — the route every Kubernetes pod, docker stop and systemd unit takes. JS drains on natural exit, SIGINT, SIGTERM and SIGHUP; Python only on the first two. Install SIGTERM/SIGHUP handlers that drain then re-raise (JS's pattern: drain, then re-raise only if the caller has no handler of their own), taking care not to clobber user-installed handlers.

  2. atexit is never unregistered. After an explicit shutdown(), the registered _atexit_shutdown keeps the dead queue — and its whole buffer — reachable for the life of the process, one entry per queue (the per-request-SDK shape), and runs a redundant second shutdown at exit. JS now removes its beforeExit/signal listeners at the end of shutdown(); Python should atexit.unregister(self._atexit_shutdown) at the same point.

Mirror JS's tests where they translate: listener/hook release after shutdown, idempotence across a second shutdown, no leak across N queues.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions