Repository navigation
Announce engine closure on disposal and terminal reconnect failure - #1268
Draft
hiroshihorie wants to merge 2 commits into
Draft
hiroshihorie wants to merge 2 commits into
hiroshihorie wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the terminal engine-closure changes.
No open issues 🎉
What changed in this PR
This PR centralizes terminal engine closure so subscribers receive EngineClosingEvent before disposal or terminal reconnect cleanup begins. It complements the separate fixes for already-blocked buffer waits and disconnect-during-reconnect races.
Changes:
- Adds idempotent closure handling before Room and Engine disposal callbacks and after terminal reconnect failures.
- Rejects buffer waits started after closure while leaving recoverable reconnects open.
- Adds ten lifecycle regression tests and a patch changeset.
| File | Description |
|---|---|
test/core/engine_closing_test.dart |
Tests closure events, disposal ordering, reconnect outcomes, and post-closure waits. |
lib/src/core/room.dart |
Marks the engine closed before Room disposal callbacks run. |
lib/src/core/engine.dart |
Centralizes closure signaling and guards buffer waits after closure. |
.changes/engine-terminal-closure |
Records the lifecycle and buffer-wait fixes for release. |
Review effort: Balanced
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Disposing a Room or giving up on reconnection can tear down the engine without emitting
EngineClosingEvent. Subscribers waiting for closure never receive it. An unrecoverable reconnect also leftisClosedfalse.This change centralizes terminal closure in an idempotent internal
Engine.markClosed(). It marks the engine closed synchronously and queuesEngineClosingEventwhile the event emitter is still alive.Disposal sequence
Room.dispose()callsengine.markClosed()beforesuper.dispose()and before any disposal callbacks. This placement matters because Room's cleanup itself callsengine.cleanUp(), before it eventually callsengine.dispose(). Announcing closure only in Engine's constructor-registered disposal callback is too late for that first transport teardown.Engine.dispose()also callsmarkClosed()beforesuper.dispose(). Disposal callbacks run in reverse registration order, so callbacks registered later can safely await engine work that is already being cancelled. Engine's constructor-registered callback retains its cleanup sequence: clean up transports, dispose the emitter, dispose signal listeners, and release reliable receive state.Explicit disconnect, retry exhaustion, and unrecoverable reconnect failure use the same closure helper before cleanup. Recoverable retries and full-reconnect transport replacement do not close the engine. Buffer waits started after closure reject immediately, even if the retained channel reports a low buffer. Closing-event delivery remains asynchronous; disposal does not await completion of arbitrary event handlers.
Relationship to other fixes
This PR is based directly on
main; it is not stacked on #1267 or #1264.waitForBufferStatusLow. Retain this PR's closed/disposed guard before Fix waiting for the data channel send buffer to drain #1267's replacement implementation; that combination was tested locally.Validation
flutter analyze,dart analyze web/, repository format, import order, version consistency, andgit diff --checkpass.