Skip to content

fix: drop events tracked after close() - #97

Merged
Zaimwa9 merged 1 commit into
mainfrom
fix/no-events-after-close
Oct 6, 2026
Merged

Zaimwa9 merged 1 commit into
mainfrom
fix/no-events-after-close

Conversation

@Zaimwa9

@Zaimwa9 Zaimwa9 commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Thanks for submitting a PR! Please check the boxes below:

  • I have read the Contributing Guide.
  • I have added information to docs/ if required so people know about the feature.
  • I have filled in the "Changes" section below.
  • I have filled in the "How did you test this code" section below.

Changes

Follow-up to #94. close() cancels the flush timer and flushes once, but the EventProcessor stayed live, so trackEvent, trackExposureEvent and getExperimentFlag called after close() kept buffering events that nothing would ever send. The processor now marks itself stopped: later events are logged and dropped, while the teardown flush and an explicit flushEvents() still complete.

How did you test this code?

flutter analyze clean, flutter test 165 passing. New cases: events tracked after close() are dropped for all three entry points; the buffer pending at close() is still posted.

@Zaimwa9
Zaimwa9 requested a review from a team as a code owner October 5, 2026 09:38
@Zaimwa9
Zaimwa9 requested review from talissoncosta and removed request for a team October 5, 2026 09:38
@Zaimwa9
Zaimwa9 merged commit b8af810 into main Oct 6, 2026
4 checks passed
@Zaimwa9
Zaimwa9 deleted the fix/no-events-after-close branch October 6, 2026 06:11
Zaimwa9 added a commit that referenced this pull request Nov 10, 2026
Part of Flagsmith/flagsmith-private#302 (epic
Flagsmith/flagsmith-private#362). Covers the background flush and the
awaitable `close()`.

## Changes
- Buffered events are flushed when the app becomes `hidden`, `paused` or
`detached`. `inactive` is skipped because it fires on Control Center and
incoming calls. If the client is created before the Flutter binding is
initialised, the lifecycle hook is skipped with a debug log instead of
throwing.
- `close()` returns `Future<void>` and takes an optional `timeout` (10 s
by default). It completes once the final POST finishes or the timeout
passes, and never throws. Events tracked after `close()` are still
dropped (#97).
- README documents when events are flushed, the best-effort limits (iOS
suspension, force-quit, web unload) and shutdown.

## API change
`close()` changes from `void` to `Future<void>`. Existing
`client.close();` calls still compile. Subclasses that override
`close()` and fakes that implement `FlagsmithClient` need to update
their signature.

## Tests
- Background flush on `hidden`/`paused`/`detached`; no flush on
`inactive`.
- `await close()` waits for the POST; `close(timeout:)` returns when a
slow POST outlasts the timeout.
- `close()` removes the lifecycle listener.
- Creating a client before the Flutter binding exists doesn't throw (own
test file, so it doesn't depend on test order).
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.

2 participants