Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly close connections in the proxy. #324

Merged
merged 3 commits into from
Sep 18, 2023
Merged

Conversation

sfc-gh-srhodes
Copy link
Collaborator

The proxy was doing a bunch of work to properly call ClientClose on streams when clients had no more messages, but it neglected to close the underlying ClientConn used by the stream. This leaked the stream on each outwards dial to a sansshell server, eventually accumulating many client connections all doing nothing but keepalive.

To fix this, I'm closing the connection to a server after we've finished all send/recv calls with the server and we're about to return the final ServerClose message back to the client.

This is reproducable by launching the proxy+server and making a bunch of calls

% go run ./cmd/sansshell-server
% go run ./cmd/proxy-server
% for f in $(seq 20); do ./sanssh --proxy=localhost:50043 --targets=localhost:50042 file read /etc/hosts& done

Then watch the keepalive goroutine count at http://localhost:50044/debug/pprof/goroutine?debug=1 go up and up.

I've updated the README a bit so that it has better instructions for running the proxy.

The proxy was doing a bunch of work to properly call ClientClose on streams when clients had no more messages, but it neglected to close the underlying ClientConn used by the stream. This leaked the stream on each outwards dial to a sansshell server, eventually accumulating many client connections all doing nothing but keepalive.

To fix this, I'm closing the connection to a server after we've finished all send/recv calls with the server and we're about to return the final ServerClose message back to the client.

This is reproducable by launching the proxy+server and making a bunch of calls

```
% go run ./cmd/sansshell-server
% go run ./cmd/proxy-server
% for f in $(seq 20); do ./sanssh --proxy=localhost:50043 --targets=localhost:50042 file read /etc/hosts& done
```

Then watch the keepalive goroutine count at http://localhost:50044/debug/pprof/goroutine?debug=1 go up and up.

I've updated the README a bit so that it has better instructions for running the proxy.
@sfc-gh-srhodes sfc-gh-srhodes enabled auto-merge (squash) September 18, 2023 22:21
@sfc-gh-srhodes sfc-gh-srhodes merged commit 31b72a5 into main Sep 18, 2023
@sfc-gh-srhodes sfc-gh-srhodes deleted the srhodes-close-conns branch September 18, 2023 22:31
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.

2 participants