File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -122,6 +122,14 @@ type wantConn struct {
122122 result chan wantConnResult // channel to deliver connection or error
123123}
124124
125+ // getCtxForDial returns context for dial or nil if connection was delivered or canceled.
126+ func (w * wantConn ) getCtxForDial () context.Context {
127+ w .mu .Lock ()
128+ defer w .mu .Unlock ()
129+
130+ return w .ctx
131+ }
132+
125133func (w * wantConn ) tryDeliver (cn * Conn , err error ) bool {
126134 w .mu .Lock ()
127135 defer w .mu .Unlock ()
@@ -576,12 +584,13 @@ func (p *ConnPool) asyncNewConn(ctx context.Context) (*Conn, error) {
576584 defer w .cancelCtx ()
577585 defer func () { <- p .dialsInProgress }() // Release connection creation permission
578586
579- cn , cnErr := p .newConn (w .ctx , true )
587+ dialCtx := w .getCtxForDial ()
588+ cn , cnErr := p .newConn (dialCtx , true )
580589 delivered := w .tryDeliver (cn , cnErr )
581590 if cnErr == nil && delivered {
582591 return
583592 } else if cnErr == nil && ! delivered {
584- p .Put (w . ctx , cn )
593+ p .Put (dialCtx , cn )
585594 } else { // freeTurn after error
586595 p .freeTurn ()
587596 }
You can’t perform that action at this time.
0 commit comments