feat(api): add non-blocking Tracker close-and-drain completion receipt - #429
Open
ThoriaDevelopment wants to merge 1 commit into
Open
ThoriaDevelopment wants to merge 1 commit into
ThoriaDevelopment wants to merge 1 commit into
Conversation
Close a tracker and return a completion stage that proves all tracker-originated work has ended, so plugins can safely remove the owning entity without a race. Refs toxicity188#417.
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.
Summary
Implements #417: a non-blocking completion receipt that proves a
Trackerhas fully drained before the plugin removes the owning entity.Tracker#closeAndDrain()closes the tracker and returns aCompletionStage<Void>that completes only when all tracker-originated work has ended:It never blocks and is safe to call from the main server thread:
Impacted modules
api(kr.toxicity.model.api.tracker.Tracker,CloseReason.DRAIN)apitest source set (new:TrackerCloseAndDrainTest+ JUnit test dependencies inapi/build.gradle.kts)How it works
tick(): once draining is requested, the next completed updater invocation (including one already in flight) runs any still-queued tasks and completes the receipt exactly once.tickingflag is set before the quiescence check, so a close racing a running updater can never complete the receipt while the updater is still inside its handler (Dekker-style ordering).close(CloseReason.DRAIN)cancels the scheduler without interrupting the in-flight updater — interrupting could abort pipeline work mid-flight before the receipt completes. Legacy reasons (REMOVE,DESPAWN,PLUGIN_DISABLE) keep their previous interrupt semantics.task(...)rejects new work from the moment draining begins; tasks queued before the drain are flushed before completion or invalidated.start()now refuses to reschedule a closed tracker (a latespawnPacketHandlercallback could previously restart the scheduler after close).pipeline.despawn()runs before the receipt completes, satisfying postcondition 6; the constructor's late skin-context callback is invalidated once the tracker closes, satisfying postcondition 5/7.Compatibility
closeAndDrain(),@since 3.4.2, matching the repo's@sinceversioning convention). No existing signatures changed.close()andshutdown()keep the same interrupt/despawn semantics for all pre-existing reasons. One deliberate behavior change: a throwing close handler is now logged and still fully tears the tracker down (previously teardown was skipped and the exception propagated).Tests / checks run
TrackerCloseAndDrainTest(7 tests, all green): immediate completion when idle; queued-task invalidation after drain; queued work runs before completion; latch-blocked updater defers the receipt until it returns; reentrant/idempotent closes; exceptional completion for failing queued tasks and close handlers.:bettermodel-api:checkand:bettermodel-api:checkLicenses— pass.This contribution was prepared with AI assistance (Codebuff) and reviewed by a human before submission.