Skip to content

fix: daemon exit on RPC shutdown with --enable-gc - #11447

Open
lidel wants to merge 1 commit into
masterfrom
fix/daemon-rpc-shutdown-gc
Open

fix: daemon exit on RPC shutdown with --enable-gc#11447
lidel wants to merge 1 commit into
masterfrom
fix/daemon-rpc-shutdown-gc

Conversation

@lidel

@lidel lidel commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Problem

A daemon started with --enable-gc answered ipfs shutdown (POST /api/v0/shutdown) by closing the node and then never exited: the periodic GC loop waited on the command's request context, which only a signal cancels, so daemonFunc never finished draining its error channels. Supervisors that stop Kubo over the RPC API waited on the process forever, and Internal.ShutdownTimeout could not help because its watchdog arms only after that drain. Present since #1495.

Fix

  • derive the GC context from req.Context and cancel it when node.Context() ends too, so the loop stops on node close; a signal still aborts an in-flight sweep before the OnStop hooks close the datastore (rationale in maybeRunGC)
  • TestDaemonRPCShutdown stops a daemon over RPC, with and without --enable-gc, and waits on the process; the harness StopDaemon sends SIGTERM and would have hidden this

Out of scope: on the RPC path a running sweep still overlaps app.Stop until the node context ends, and the shutdown watchdog still does not cover the RPC path.

maybeRunGC ran PeriodicGC on req.Context, which the RPC shutdown
command never cancels (it only closes the node), so gcErrc never
closed and daemonFunc blocked in merge() forever. Cancel the GC
context on node close as well, keeping req.Context so a signal still
aborts an in-flight sweep before the OnStop hooks close the datastore.

Closes #11424
@lidel lidel mentioned this pull request Sep 3, 2026
62 tasks
@lidel
lidel marked this pull request as ready for review September 3, 2026 22:47
@lidel
lidel requested a review from a team as a code owner September 3, 2026 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

daemon --enable-gc never exits on ipfs shutdown (RPC), only on SIGINT/SIGTERM

1 participant