You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
func (s *server) run() {
defer s.wg.Done()
for {
client, err := s.netListener.Accept()
if err != nil {
break
}
s.handle(client)
}
}
netListener is commonly a TLS listener, which can return an error from Accept for many reasons. Breaking out of the loop stops the server from accepting new connections. And, as far as I can tell, there is no way to know from the outside (since run gets called in a goroutine) that this has happened.
The text was updated successfully, but these errors were encountered:
Actually, I am wrong. TLS wont return handshake errors from Accept. So this issue is less serious than I thought. I don't know if we can assume Accept will only return an error if closed, so it might still be a good idea to guard against that case.
stefanba3
changed the title
If listener.Accept returns an error (e.g. a TLS certificate error) then the server stops responding
If listener.Accept returns an error then the server stops responding
Aug 10, 2021
I think this code could use errors.Is(err, net.ErrClosed) to determine if the loop should break. Other errors should probably be logged, but continue to Accept().
For example, here:
netListener
is commonly a TLS listener, which can return an error from Accept for many reasons. Breaking out of the loop stops the server from accepting new connections. And, as far as I can tell, there is no way to know from the outside (sincerun
gets called in a goroutine) that this has happened.The text was updated successfully, but these errors were encountered: