Skip to content

fix(memory): release held locks when the Streamable HTTP server stops - #5596

Merged
cliffhall merged 1 commit into
v2/mainfrom
v2/fix/5595-memory-http-lock-cleanup
Nov 18, 2026
Merged

cliffhall merged 1 commit into
v2/mainfrom
v2/fix/5595-memory-http-lock-cleanup

Conversation

@cliffhall

Copy link
Copy Markdown
Member

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, called installLockCleanup() (#5485). Closing the HTTP listener does not wait for a tool call that is mid-write, so the process.exit() that follows left <memory file>.lock behind for the next writer to wait out. A second signal took the default action, with no exit event at all.

  • installExitLockCleanup() registers the exit hook 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.
  • A second SIGINT or SIGTERM exits at once with that signal's status (130 or 143), through the same hook.

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

  • Server: @modelcontextprotocol/server-memory
  • Changes: index.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:gate exited 0 on af86b990.
  • Three new tests in __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.
  • Inspector CLI 2.12.0 over HTTP, 2026-07-28 era, with the memory file a FIFO so create_entities holds the lock: after SIGTERM the lock is gone on this branch, and still present on the v2.5.0 candidate 8e44b8fa.
  • LLM client: Claude Code 2.1.327, headless, connected to this build over Streamable HTTP: create_entities then read_graph returned the entity; the server then exited 0 on SIGTERM with no lock left.

Breaking Changes

None.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature
  • Breaking change
  • Documentation update

Checklist

  • I have read the MCP Protocol Documentation
  • My changes follow MCP security best practices
  • I have updated the server's README accordingly (no change needed: its lock section already describes this behavior)
  • I have added a changeset (patch)
  • I have tested this with an LLM client
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have documented all environment variables and configuration options (none added)

🤖 Generated with Claude Code

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>
@cliffhall cliffhall added the v2 label Nov 18, 2026
@changeset-bot

changeset-bot Bot commented Nov 18, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: af86b99

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@modelcontextprotocol/server-memory Patch

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

@github-actions

Copy link
Copy Markdown
Contributor

memory: MCP interface diff

Base: 8e44b8fac205 (Merge pull request #5537 from modelcontextprotocol/changeset-release/v2/main)
Head: the build in this checkout, at 989c5ac04a07 (Merge af86b99 into 8e44b8f)

Diffed because it was named (--server).

✅ No interface changes detected.

Tools Prompts Resources Resource templates
Base 9 0 1 0
Head 9 0 1 0

Updated by this run for af86b99080b0f4af52ca6a8f4f1e043921ec6140.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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

@cliffhall
cliffhall merged commit 69f8a37 into v2/main Nov 18, 2026
46 checks passed
@cliffhall
cliffhall deleted the v2/fix/5595-memory-http-lock-cleanup branch November 18, 2026 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

memory: over Streamable HTTP, shutdown during an in-flight write leaves the lock file behind

2 participants