Repository navigation
fix(memory): release held locks when the Streamable HTTP server stops - #5596
Conversation
Over Streamable HTTP, run() never registered the exit hook that removes a lock file the process still holds: only main(), the stdio path, called installLockCleanup(). Closing the listener does not wait for a tool call that is mid-write, so the process.exit() after it left the lock for the next writer to wait out. A second signal took the default action, with no exit event at all. run() now registers the exit hook, and a second SIGINT or SIGTERM exits at once with that signal's status, through the same hook. Closes #5595 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: cliffhall <cliff@futurescale.com>
🦋 Changeset detectedLatest commit: af86b99 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
| Tools | Prompts | Resources | Resource templates | |
|---|---|---|---|---|
| Base | 9 | 0 | 1 | 0 |
| Head | 9 | 0 | 1 | 0 |
Updated by this run for af86b99080b0f4af52ca6a8f4f1e043921ec6140.
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the HTTP shutdown lock-cleanup change.
No open issues 🎉
What changed in this PR
Fixes memory-server lock cleanup during Streamable HTTP shutdown, extending the existing stdio behavior to address #5595.
Changes:
- Shares a one-time exit cleanup hook between stdio and HTTP startup.
- Preserves graceful shutdown on the first signal; a second signal exits immediately through the cleanup hook.
- Adds shutdown regression tests and a patch changeset.
| File | Description |
|---|---|
src/memory/index.ts |
Registers HTTP exit cleanup and handles repeated shutdown signals. |
src/memory/__tests__/http.test.ts |
Tests cleanup registration, repeated signals, and lock removal after a real SIGTERM. |
.changeset/memory-http-lock-cleanup.md |
Records the memory-server patch and shutdown fixes. |
Review effort: Balanced
Closes #5595
Description
Over Streamable HTTP, the memory server never registered the exit hook that removes a lock file the process still holds: only
main(), the stdio path, calledinstallLockCleanup()(#5485). Closing the HTTP listener does not wait for a tool call that is mid-write, so theprocess.exit()that follows left<memory file>.lockbehind for the next writer to wait out. A second signal took the default action, with noexitevent at all.installExitLockCleanup()registers theexithook alone, once.installLockCleanup()(stdio) now calls it and still takes over the signals.run()calls it before serving HTTP, keeping its graceful close on the first signal.Found by the Copilot review of the v2.5.0 merge PR (#5592). Streamable HTTP for this server is new in v2.5.0, so no published version has the defect.
Server Details
@modelcontextprotocol/server-memoryindex.ts(startup and shutdown),__tests__/http.test.ts.Motivation and Context
#5595. The README already says a server stopped by SIGINT or SIGTERM removes the lock it holds; this makes that true over HTTP as well.
How Has This Been Tested?
npm run local:gateexited 0 onaf86b990.__tests__/http.test.ts; two fail with the fix removed (expected [] to include [Function releaseHeldLocks], and the lock file still present after SIGTERM). One spawns the built server over Streamable HTTP, holds the lock, and sends a real SIGTERM.create_entitiesholds the lock: after SIGTERM the lock is gone on this branch, and still present on the v2.5.0 candidate8e44b8fa.create_entitiesthenread_graphreturned the entity; the server then exited 0 on SIGTERM with no lock left.Breaking Changes
None.
Types of changes
Checklist
🤖 Generated with Claude Code