Skip to content

Count TCP sockets from creation - #3707

Merged
fibonacci1729 merged 1 commit into
spinframework:mainfrom
carsonfarmer:cf/fix-tcp-socket-quota
Sep 2, 2026
Merged

Count TCP sockets from creation#3707
fibonacci1729 merged 1 commit into
spinframework:mainfrom
carsonfarmer:cf/fix-tcp-socket-quota

Conversation

@carsonfarmer

@carsonfarmer carsonfarmer commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Fixes #3706.

TCP socket creation already opens an operating-system socket, but Spin did not acquire quota until connect. Unconnected sockets could therefore bypass max_socket_connections and max_total_connections.

This change acquires quota when P2 or P3 creates the socket. The existing resource tracking releases it when the socket is dropped.

Tests cover both APIs, socket and instance cleanup, and shared limits.

Tests

  • cargo test -p spin-factor-wasi
  • cargo test -p spin-factor-outbound-networking
  • make test-unit
  • make lint
  • make build

@itowlson
itowlson requested review from dicej, lann and rylev September 1, 2026 22:24
@carsonfarmer
carsonfarmer marked this pull request as draft September 2, 2026 00:00
@carsonfarmer

carsonfarmer commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Apologies, I think I can see a simpler way to handle this. Moving to draft until I can properly confirm!

Much better/simpler.

Acquire socket quota before Wasmtime creates the host socket. Track the
permit with the socket resource so unconnected sockets cannot bypass the
configured limit.

Signed-off-by: carsonfarmer <carson.farmer@gmail.com>
Co-authored-by: Codex <noreply@openai.com>
@carsonfarmer
carsonfarmer force-pushed the cf/fix-tcp-socket-quota branch from bf7a63b to 271e5fb Compare September 2, 2026 01:30
@carsonfarmer
carsonfarmer marked this pull request as ready for review September 2, 2026 03:19

@dicej dicej 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.

LGTM, thanks! @rylev implemented the original connection limiting code, so it will be good to have his eyes on this.

@fibonacci1729
fibonacci1729 merged commit d716499 into spinframework:main Sep 2, 2026
17 checks passed
@carsonfarmer
carsonfarmer deleted the cf/fix-tcp-socket-quota branch September 2, 2026 21:32
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.

TCP socket limits do not count unconnected sockets

3 participants