mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: fix closeMutex unlock bug (#17259)
Fixes https://github.com/coder/internal/issues/550 Classic return before unlocking bug.
This commit is contained in:
+14
-6
@@ -1518,14 +1518,11 @@ func (a *agent) runCoordinator(ctx context.Context, tClient tailnetproto.DRPCTai
|
||||
a.logger.Info(ctx, "connected to coordination RPC")
|
||||
|
||||
// This allows the Close() routine to wait for the coordinator to gracefully disconnect.
|
||||
a.closeMutex.Lock()
|
||||
if a.isClosed() {
|
||||
return nil
|
||||
disconnected := a.setCoordDisconnected()
|
||||
if disconnected == nil {
|
||||
return nil // already closed by something else
|
||||
}
|
||||
disconnected := make(chan struct{})
|
||||
a.coordDisconnected = disconnected
|
||||
defer close(disconnected)
|
||||
a.closeMutex.Unlock()
|
||||
|
||||
ctrl := tailnet.NewAgentCoordinationController(a.logger, network)
|
||||
coordination := ctrl.New(coordinate)
|
||||
@@ -1547,6 +1544,17 @@ func (a *agent) runCoordinator(ctx context.Context, tClient tailnetproto.DRPCTai
|
||||
return <-errCh
|
||||
}
|
||||
|
||||
func (a *agent) setCoordDisconnected() chan struct{} {
|
||||
a.closeMutex.Lock()
|
||||
defer a.closeMutex.Unlock()
|
||||
if a.isClosed() {
|
||||
return nil
|
||||
}
|
||||
disconnected := make(chan struct{})
|
||||
a.coordDisconnected = disconnected
|
||||
return disconnected
|
||||
}
|
||||
|
||||
// runDERPMapSubscriber runs a coordinator and returns if a reconnect should occur.
|
||||
func (a *agent) runDERPMapSubscriber(ctx context.Context, tClient tailnetproto.DRPCTailnetClient24, network *tailnet.Conn) error {
|
||||
defer a.logger.Debug(ctx, "disconnected from derp map RPC")
|
||||
|
||||
Reference in New Issue
Block a user