grpc: clarify the use of transport.ErrConnClosing from createTransport() (#4757)

This commit is contained in:
Easwar Swaminathan 2021-09-13 11:50:52 -07:00 committed by GitHub
parent 77ffb2ef31
commit 5bfc05fb0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 0 deletions

View File

@ -1329,6 +1329,9 @@ func (ac *addrConn) createTransport(addr resolver.Address, copts transport.Conne
select {
case <-connectCtx.Done():
// We didn't get the preface in time.
// The error we pass to Close() is immaterial since there are no open
// streams at this point, so no trailers with error details will be sent
// out. We just need to pass a non-nil error.
newTr.Close(transport.ErrConnClosing)
if connectCtx.Err() == context.DeadlineExceeded {
err := errors.New("failed to receive server preface within timeout")
@ -1352,8 +1355,13 @@ func (ac *addrConn) createTransport(addr resolver.Address, copts transport.Conne
// state. tearDown() would have set the state to `Shutdown`, but
// would not have closed the transport since ac.transport would not
// been set at that point.
//
// We run this in a goroutine because newTr.Close() calls onClose()
// inline, which requires locking ac.mu.
//
// The error we pass to Close() is immaterial since there are no open
// streams at this point, so no trailers with error details will be sent
// out. We just need to pass a non-nil error.
go newTr.Close(transport.ErrConnClosing)
return nil
}