Skip to content

feat(sdk): add Surfnet.stop() for graceful shutdown#641

Closed
amilz wants to merge 1 commit intosolana-foundation:mainfrom
amilz:aaron/dev-467-add-surfnetstop-to-surfpool-sdk-for-graceful-shutdown
Closed

feat(sdk): add Surfnet.stop() for graceful shutdown#641
amilz wants to merge 1 commit intosolana-foundation:mainfrom
amilz:aaron/dev-467-add-surfnetstop-to-surfpool-sdk-for-graceful-shutdown

Conversation

@amilz
Copy link
Copy Markdown

@amilz amilz commented Apr 30, 2026

Summary

  • Add Surfnet::stop(&mut self) to the Rust SDK that sends SimnetCommand::Terminate and blocks until both RPC servers (HTTP + WS) acknowledge shutdown via SimnetEvent::Shutdown, with a 5s timeout.
  • Returns an error when shutdown is not confirmed so callers can treat unfreed ports as fatal instead of silently leaking sockets.
  • Surface stop() through the napi binding and TypeScript wrapper so consumers can call surfnet.stop() from afterAll test teardown.
  • Drop keeps its best-effort Terminate send when stop() was not called or failed.

Test Plan

  • cargo test -p surfpool-sdk -p surfpool-sdk-node — passes (22 + 0 tests).
  • npm test in crates/sdk-node/ — passes (6/6) including a new smoke test that calls stop() twice (idempotency on success), confirms the RPC fails after, and verifies the port is rebindable.
  • Full workspace cargo test --workspace — pre-existing flake in surfpool-core unrelated to this change (verified by stashing the diff).

Closes DEV-467

Expose a JS-callable shutdown that closes the HTTP + WebSocket RPC
servers and frees the bound port. Blocks until both servers
acknowledge shutdown (via SimnetEvent::Shutdown) or the 5s timeout
elapses; returns an error if shutdown is not confirmed so callers
can treat it as fatal rather than silently leaking sockets.

Use this from test teardown (e.g. afterAll) to avoid 'connection
reset' / 'broken pipe' warnings caused by the OS yanking sockets at
process exit.

Drop still sends Terminate as a best-effort fallback when stop()
was not called or failed.

Closes DEV-467
@amilz amilz closed this Apr 30, 2026
@amilz amilz deleted the aaron/dev-467-add-surfnetstop-to-surfpool-sdk-for-graceful-shutdown branch April 30, 2026 21:00
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.

1 participant