wait until the run loop has finished when calling session.destroy()

This commit is contained in:
Marten Seemann
2019-05-10 10:07:39 +09:00
parent c135b4f1e3
commit eee3af0757

View File

@@ -415,11 +415,11 @@ runLoop:
} }
if !s.handshakeComplete && now.Sub(s.sessionCreationTime) >= s.config.HandshakeTimeout { if !s.handshakeComplete && now.Sub(s.sessionCreationTime) >= s.config.HandshakeTimeout {
s.destroy(qerr.TimeoutError("Handshake did not complete in time")) s.destroyImpl(qerr.TimeoutError("Handshake did not complete in time"))
continue continue
} }
if s.handshakeComplete && now.Sub(s.idleTimeoutStartTime()) >= s.config.IdleTimeout { if s.handshakeComplete && now.Sub(s.idleTimeoutStartTime()) >= s.config.IdleTimeout {
s.destroy(qerr.TimeoutError("No recent network activity")) s.destroyImpl(qerr.TimeoutError("No recent network activity"))
continue continue
} }
@@ -851,6 +851,11 @@ func (s *session) closeLocal(e error) {
// destroy closes the session without sending the error on the wire // destroy closes the session without sending the error on the wire
func (s *session) destroy(e error) { func (s *session) destroy(e error) {
s.destroyImpl(e)
<-s.ctx.Done()
}
func (s *session) destroyImpl(e error) {
s.closeOnce.Do(func() { s.closeOnce.Do(func() {
if nerr, ok := e.(net.Error); ok && nerr.Timeout() { if nerr, ok := e.(net.Error); ok && nerr.Timeout() {
s.logger.Errorf("Destroying session %s: %s", s.destConnID, e) s.logger.Errorf("Destroying session %s: %s", s.destConnID, e)