MCPcopy
hub / github.com/redis/go-redis / Close

Method Close

maintnotifications/manager.go:302–340  ·  view source on GitHub ↗

Close closes the manager.

()

Source from the content-addressed store, hash-verified

300
301// Close closes the manager.
302func (hm *Manager) Close() error {
303 // Use atomic operation for thread-safe close check
304 if !hm.closed.CompareAndSwap(false, true) {
305 return nil // Already closed
306 }
307
308 // Retire connections that enabled maintnotifications before removing the
309 // pool-level listeners that process those push notifications.
310 hm.retireMaintNotificationsConns(context.Background())
311
312 // Shutdown the pool hook if it exists
313 if hm.poolHooksRef != nil {
314 // Use a timeout to prevent hanging indefinitely
315 shutdownCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
316 defer cancel()
317
318 err := hm.poolHooksRef.Shutdown(shutdownCtx)
319 if err != nil {
320 // was not able to close pool hook, keep closed state false
321 hm.closed.Store(false)
322 return err
323 }
324 // Remove the pool hook from the pool
325 if hm.pool != nil {
326 hm.pool.RemovePoolHook(hm.poolHooksRef)
327 }
328 }
329
330 // Clear all active operations
331 hm.activeMovingOps.Range(func(key, value interface{}) bool {
332 hm.activeMovingOps.Delete(key)
333 return true
334 })
335
336 // Reset counter
337 hm.activeOperationCount.Store(0)
338
339 return nil
340}
341
342// GetState returns current state using atomic counter for lock-free operation.
343func (hm *Manager) GetState() State {

Calls 4

WithTimeoutMethod · 0.80
ShutdownMethod · 0.65
RemovePoolHookMethod · 0.65