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

Fix double closure of sockets for websocket_agent #334

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

k311093
Copy link
Collaborator

@k311093 k311093 commented Jul 17, 2024

At websocket_agent, wsWrapper.Close() is executed twice, at deferred function and inside go routine. Call wsWrapper.Close() only at go routine that writes data to the wsWrapper.

Also move tcpConn.Close() after io.Copy(...) to avoid confusion.

At websocket_agent, wsWrapper.Close() is executed twice, at deferred
function and inside go routine. Call wsWrapper.Close() only at go
routine that writes data to the wsWrapper.

Also move tcpConn.Close() after io.Copy(...) to avoid confusion.
go func() {
io.Copy(wsWrapper, tcpConn)
wsWrapper.Close()
}()
io.Copy(tcpConn, wsWrapper)
tcpConn.Close()
Copy link
Member

Choose a reason for hiding this comment

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

This one should stay as it was, with the defer in line 1275. It has the same effect of closing at the end of the function, but with the added benefit of closing the socket even with an early return in case of errors.

I wrongly suggested before that this one needed fixing because I had the order of parameters to io.Copy inverted. Sorry about that.

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