fix(session,bulk): clean up failed engine init, concurrent create, and bulk batch memory#600
Merged
Merged
Conversation
…d bulk batch memory - On engine.initialize() failure, evict the half-built engine from the map and tear it down instead of leaving an orphan: previously a failed start wedged the session at 'already started' with a leaked Chromium/socket permanently holding a concurrency slot. - Translate a name UNIQUE-constraint violation on session create to 409 Conflict (matching the pre-check) instead of leaking a raw 500 when two concurrent same-name creates race past the check. - Cap concurrently-processing bulk batches per process (BULK_MAX_CONCURRENT_BATCHES, 0=unlimited, generous default), rejecting before a row is persisted so a burst can't hold an unbounded number of full message sets in memory.
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
Three availability / resource-exhaustion fixes in session lifecycle and bulk send.
Changes
initializeEngineregisters the engine in the map before callingengine.initialize(). If that rejected, the engine was left behind: the session wedged at "already started", a Chromium/socket leaked, and a concurrency slot was consumed forever.start()now catches an init failure, evicts the engine, tears it down (destroyEngineSafely), records the reason, and marks the session FAILED before rethrowing.create()'s name check was a check-then-insert TOCTOU; two concurrent same-name creates both passed it and the second hit the DB name UNIQUE constraint, surfacing as a raw 500. The insert is now wrapped so a unique-violation maps to the same 409 Conflict as the pre-check.BULK_MAX_CONCURRENT_BATCHES, 0 = unlimited, generous default) now rejects a new batch before persisting a row when too many are in flight.Verification
npm run build✓ ·npm run lint✓ ·npm test✓ (1886/1886). Tests: init-failure evicts + tears down the engine; a unique-violation on create maps to 409; the bulk cap rejects before persisting.