File tree Expand file tree Collapse file tree 3 files changed +10
-11
lines changed
Expand file tree Collapse file tree 3 files changed +10
-11
lines changed Original file line number Diff line number Diff line change @@ -145,7 +145,6 @@ func (s *resubscribeSub) loop() {
145145func (s * resubscribeSub ) subscribe () Subscription {
146146 subscribed := make (chan error )
147147 var sub Subscription
148- retry:
149148 for {
150149 s .lastTry = mclock .Now ()
151150 ctx , cancel := context .WithCancel (context .Background ())
@@ -157,19 +156,19 @@ retry:
157156 select {
158157 case err := <- subscribed :
159158 cancel ()
160- if err != nil {
161- // Subscribing failed, wait before launching the next try.
162- if s .backoffWait () {
163- return nil
159+ if err == nil {
160+ if sub == nil {
161+ panic ("event: ResubscribeFunc returned nil subscription and no error" )
164162 }
165- continue retry
163+ return sub
166164 }
167- if sub == nil {
168- panic ("event: ResubscribeFunc returned nil subscription and no error" )
165+ // Subscribing failed, wait before launching the next try.
166+ if s .backoffWait () {
167+ return nil // unsubscribed during wait
169168 }
170- return sub
171169 case <- s .unsub :
172170 cancel ()
171+ <- subscribed // avoid leaking the s.fn goroutine.
173172 return nil
174173 }
175174 }
Original file line number Diff line number Diff line change @@ -102,7 +102,7 @@ func TestResubscribe(t *testing.T) {
102102func TestResubscribeAbort (t * testing.T ) {
103103 t .Parallel ()
104104
105- done := make (chan error )
105+ done := make (chan error , 1 )
106106 sub := Resubscribe (0 , func (ctx context.Context ) (Subscription , error ) {
107107 select {
108108 case <- ctx .Done ():
Original file line number Diff line number Diff line change @@ -287,7 +287,7 @@ func (n *ExecNode) Stop() error {
287287 if err := n .Cmd .Process .Signal (syscall .SIGTERM ); err != nil {
288288 return n .Cmd .Process .Kill ()
289289 }
290- waitErr := make (chan error )
290+ waitErr := make (chan error , 1 )
291291 go func () {
292292 waitErr <- n .Cmd .Wait ()
293293 }()
You can’t perform that action at this time.
0 commit comments