releaseWorkerSocket returns a pre-bound socket to the pool for reuse, or closes the listener and removes the socket file for non-pre-bound sockets. Safe to call multiple times; only the first call takes effect. This prevents a race between ShutdownAll and HealthCheckLoop both calling this on the sam
(w *ManagedWorker)
| 285 | func (p *FlightWorkerPool) returnPrebound(ps *preboundSocket) { |
| 286 | p.preboundMu.Lock() |
| 287 | defer p.preboundMu.Unlock() |
| 288 | p.prebound = append(p.prebound, ps) |
| 289 | } |
| 290 | |
| 291 | // releaseWorkerSocket returns a pre-bound socket to the pool for reuse, or |
| 292 | // closes the listener and removes the socket file for non-pre-bound sockets. |
| 293 | // Safe to call multiple times; only the first call takes effect. This prevents |
| 294 | // a race between ShutdownAll and HealthCheckLoop both calling this on the same |
| 295 | // worker, which could otherwise return a pre-bound socket to the pool twice. |
| 296 | func (p *FlightWorkerPool) releaseWorkerSocket(w *ManagedWorker) { |
| 297 | w.releaseOnce.Do(func() { |
| 298 | if w.prebound != nil { |
| 299 | // Verify the socket file still exists before returning to the pool. |
| 300 | // After an upgrade, the bind mount may be gone and the file missing. |
| 301 | if _, err := os.Stat(w.prebound.socketPath); err != nil { |
| 302 | _ = w.prebound.listener.Close() |
| 303 | } else { |
| 304 | p.returnPrebound(w.prebound) |
| 305 | } |
| 306 | w.prebound = nil |
| 307 | } else { |
| 308 | if w.parentListener != nil { |