Skip to content

Commit

Permalink
fix: Resolve connection leakage that can cause too many open files, e…
Browse files Browse the repository at this point in the history
…specially with stream input
  • Loading branch information
driskell committed Feb 26, 2024
1 parent 4fd8be8 commit 39f87a9
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lc-lib/transports/tcp/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ func newConnection(ctx context.Context, socket connectionSocket, protocolFactory

// Run starts the connection and all its routines
func (t *connection) run(startedCallback func()) error {
defer func () {
// Cleanup
t.socket.Close()

// Ensure context resources are cleaned up
t.shutdownFunc()
}()

t.rwBuffer.Reader = bufio.NewReader(t.socket)
t.rwBuffer.Writer = bufio.NewWriter(t.socket)

Expand Down Expand Up @@ -122,12 +130,6 @@ func (t *connection) run(startedCallback func()) error {
// Wait for sender to complete due to Teardown or nil sent
t.wait.Wait()

// Cleanup
t.socket.Close()

// Ensure context resources are cleaned up
t.shutdownFunc()

// If we had no receiver error, did sender save one when it shutdown?
if err == nil {
return t.senderErr
Expand Down

0 comments on commit 39f87a9

Please sign in to comment.