File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -712,7 +712,9 @@ func (s *Connection) shutdown(closeTimeout time.Duration) {
712712
713713 var timeout <- chan time.Time
714714 if closeTimeout > time .Duration (0 ) {
715- timeout = time .After (closeTimeout )
715+ timer := time .NewTimer (closeTimeout )
716+ defer timer .Stop ()
717+ timeout = timer .C
716718 }
717719 streamsClosed := make (chan bool )
718720
@@ -739,7 +741,15 @@ func (s *Connection) shutdown(closeTimeout time.Duration) {
739741 }
740742
741743 if err != nil {
742- duration := 10 * time .Minute
744+ // default to 1 second
745+ duration := time .Second
746+ // if a closeTimeout was given, use that, clipped to 1s-10m
747+ if closeTimeout > time .Second {
748+ duration = closeTimeout
749+ }
750+ if duration > 10 * time .Minute {
751+ duration = 10 * time .Minute
752+ }
743753 timer := time .NewTimer (duration )
744754 defer timer .Stop ()
745755 select {
@@ -806,7 +816,9 @@ func (s *Connection) CloseWait() error {
806816func (s * Connection ) Wait (waitTimeout time.Duration ) error {
807817 var timeout <- chan time.Time
808818 if waitTimeout > time .Duration (0 ) {
809- timeout = time .After (waitTimeout )
819+ timer := time .NewTimer (waitTimeout )
820+ defer timer .Stop ()
821+ timeout = timer .C
810822 }
811823
812824 select {
You can’t perform that action at this time.
0 commit comments