File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -279,12 +279,12 @@ func (c *Client) Stop() error {
279279 }
280280
281281 c .lifecycleMutex .Lock ()
282- defer c .lifecycleMutex .Unlock ()
283282
284283 if c .lifecycleState != clientStateRunning {
285284 if busyLocked {
286285 c .busyMutex .Unlock ()
287286 }
287+ c .lifecycleMutex .Unlock ()
288288 return nil
289289 }
290290
@@ -300,6 +300,9 @@ func (c *Client) Stop() error {
300300 if ! c .IsDone () {
301301 msg := NewMsgDone ()
302302 sendErr = c .SendMessage (msg )
303+ if errors .Is (sendErr , protocol .ErrProtocolShuttingDown ) {
304+ sendErr = nil
305+ }
303306 _ = c .WaitSendQueueDrained (250 * time .Millisecond )
304307 }
305308 if busyLocked {
@@ -312,14 +315,18 @@ func (c *Client) Stop() error {
312315 c .readyForNextBlockChan = nil
313316 }
314317
315- // Stop/unregister the underlying protocol instance.
318+ // Stop/unregister the underlying protocol instance, then wait for it to
319+ // finish so IsDone reports the completed shutdown when Stop returns.
320+ doneChan := c .DoneChan ()
316321 c .Protocol .Stop ()
317322 c .lifecycleState = clientStateStopped
318323 // Unblock any goroutine waiting for an in-progress start.
319324 if c .startingDone != nil {
320325 close (c .startingDone )
321326 c .startingDone = nil
322327 }
328+ c .lifecycleMutex .Unlock ()
329+ <- doneChan
323330 return sendErr
324331}
325332
You can’t perform that action at this time.
0 commit comments