MCPcopy Create free account
hub / github.com/dadgar/onecache / reap

Method reap

onecache/pool.go:347–382  ·  view source on GitHub ↗

Reap is used to close conns open over maxTime

()

Source from the content-addressed store, hash-verified

345
346// Reap is used to close conns open over maxTime
347func (p *connPool) reap() {
348 for {
349 // Sleep for a while
350 select {
351 case <-p.shutdownCh:
352 return
353 case <-time.After(time.Second):
354 }
355
356 // Reap all old conns
357 p.Lock()
358 var removed []string
359 now := time.Now()
360 for host, conn := range p.pool {
361 // Skip recently used connections
362 if now.Sub(conn.lastUsed) < p.maxTime {
363 continue
364 }
365
366 // Skip connections with active streams
367 if atomic.LoadInt32(&conn.refCount) > 0 {
368 continue
369 }
370
371 // Close the conn
372 conn.Close()
373
374 // Remove from pool
375 removed = append(removed, host)
376 }
377 for _, host := range removed {
378 delete(p.pool, host)
379 }
380 p.Unlock()
381 }
382}

Callers 1

newPoolFunction · 0.95

Calls 1

CloseMethod · 0.45

Tested by

no test coverage detected