-
Notifications
You must be signed in to change notification settings - Fork 37
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 server open connection leaks #15
Conversation
💚 CLA has been signed |
c35f153
to
bc74df5
Compare
bc74df5
to
84b1d45
Compare
@elastic/agent |
@@ -238,6 +238,8 @@ func (s *server) handle(client net.Conn) { | |||
go func() { | |||
var buf [1]byte | |||
if _, err := io.ReadFull(client, buf[:]); err != nil { | |||
close(sig) | |||
client.Close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch. We should always close sig
. How about changing the go function to always close sig via defer? In that case the second go-routine will do the client.Close always.
e.g.
go func() {
defer close(sig)
var buf [1]byte
// keep rest as is
}()
Actually we might consider to remove the client.Close
at the end, as the second go-routine in handle
waits for a) the server shutting down or b) the handling go-routine having finished. If sig
is closed properly we will always close the client
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, defer
would be better here. Actually, the second go-routine will not do the client.Close
after sig closed as it placed in a difference case and the client connection will be used in the channel. So I kept the client.Close
here.
84b1d45
to
a53f084
Compare
Change looks good. Thanks. |
Hi,
I think we should close connection & sig in the server after io.ReadFull errors.
Some healthcheck method (K8s, AWS ELB Target Groups, etc.) will close connection and trigger the EOF error here.