Skip to content

Buffered events are lost when the process ends before a flush or tick #32

Closed

Description

@rennf93

Adding an event or metric to the buffer wrote it to Redis immediately (persist-on-enqueue). That put a Redis round trip, up to the command timeout (5s by default) while Redis is slow, on the request path of every host call to sendEvent() / sendMetric().

The first fix on this branch moved the write off the request path: EventBuffer::add* only marks items pending, and persistPending() writes them at the end of flushBuffer() and from tick(). The trade-off is that a request that ends before any flush or tick never wrote its items, so they were lost.

I am closing that gap wherever PHP allows. The agent registers one shutdown function when Redis persistence is attached, and it calls persistPending(). That covers normal end, exit(), an uncaught exception, a fatal error, out of memory and max_execution_time. The request path still has no Redis round trip.

What cannot be fixed: SIGKILL (the OOM killer, kill -9) and SIGTERM without a host handler run no PHP code at all. I will prove all of this with child-process tests against a real Redis (bin/test_shutdown.php) and document the two unfixable cases with the reason.

I deliberately do not call fastcgi_finish_request() from the shutdown function (it would cut off output and shutdown functions the host registers later) and I do not install a SIGTERM handler (it would override the host's).

Activity

  1. added
    bugConfirmed defect
    area: persistenceTouches Redis persistence, the Redis client adapters, or install id
    on Oct 15, 2026
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

    area: persistenceTouches Redis persistence, the Redis client adapters, or install idbugConfirmed defect

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions