MCPcopy Create free account
hub / github.com/PostHog/duckgres / releaseWorkerSocket

Method releaseWorkerSocket

controlplane/worker_mgr.go:287–305  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

285func (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.
296func (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 {

Calls 4

returnPreboundMethod · 0.95
DoMethod · 0.80
RemoveMethod · 0.80
CloseMethod · 0.65