Skip to content

[2.x] feat: drop other idle servers on client exit (#8610)#8701

Merged
eed3si9n merged 2 commits intosbt:developfrom
calm329:feat/8610-drop-idle-servers
Feb 6, 2026
Merged

[2.x] feat: drop other idle servers on client exit (#8610)#8701
eed3si9n merged 2 commits intosbt:developfrom
calm329:feat/8610-drop-idle-servers

Conversation

@calm329
Copy link
Copy Markdown
Contributor

@calm329 calm329 commented Feb 6, 2026

Summary

Implements cooperative idle server cleanup for sbtn (issue #8610). When a client disconnects from an sbt server, that server notifies all
other registered servers to shut down if they've been idle long enough and have no connected clients. This prevents accumulation of idle
background JVMs across projects.

fixes #8610

Problem

Each sbtn session leaves a background JVM server running with a 7-day idle timeout. Users working across many projects accumulate idle
servers that waste system resources (memory, file descriptors, threads).

Solution

  • Each server registers itself via a <PID>.json file in a shared proc directory (~/.cache/sbt/v2/proc/ on Linux,
    ~/Library/Caches/sbt/v2/proc/ on macOS).
  • When a client disconnects, the server sends a sbt/dropIfIdle JSON-RPC notification to all other registered servers.
  • A server receiving dropIfIdle shuts down if idle >= sbt.server.secondaryIdleTimeout (default 600s) AND has no initialized
    NetworkChannel clients.
  • Stale proc files (unreachable servers) are cleaned up on contact failure.
  • Anti-cascading: only initialized channels (real clients that completed the initialize handshake) trigger notifyOtherServers on
    disconnect. Temporary dropIfIdle connections never initialize, so their removal won't cascade.

Testing

  • Manual: started server with -Dsbt.server.secondaryIdleTimeout=5, verified proc file created, sent dropIfIdle notification, confirmed
    server drops when idle with no clients and stays alive when a client is connected.
  • Verified proc file cleanup on shutdown.

@calm329
Copy link
Copy Markdown
Contributor Author

calm329 commented Feb 6, 2026

@eed3si9n Could you please review this pr?

Copy link
Copy Markdown
Member

@eed3si9n eed3si9n left a comment

Choose a reason for hiding this comment

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

Left a minor comment, but overall LGTM. Thanks @calm329!

Copy link
Copy Markdown
Member

@eed3si9n eed3si9n left a comment

Choose a reason for hiding this comment

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

Thanks!

@eed3si9n eed3si9n merged commit 47e7133 into sbt:develop Feb 6, 2026
15 checks passed
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.

Drop other idle servers on exit

2 participants