MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / cleanClients

Method cleanClients

internal/nodes/http_client_pool.go:231–265  ·  view source on GitHub ↗

清理不使用的Client

()

Source from the content-addressed store, hash-verified

229
230// 清理不使用的Client
231func (this *HTTPClientPool) cleanClients() {
232 for range this.cleanTicker.C {
233 var nowTime = fasttime.Now().Unix()
234
235 var expiredKeys []uint64
236 var expiredClients = []*HTTPClient{}
237
238 // lookup expired clients
239 this.locker.RLock()
240 for k, client := range this.clientsMap {
241 if client.AccessTime() < nowTime-86400 ||
242 (client.IsProxyProtocol() && client.AccessTime() < nowTime-3600) { // 超过 N 秒没有调用就关闭
243 expiredKeys = append(expiredKeys, k)
244 expiredClients = append(expiredClients, client)
245 }
246 }
247 this.locker.RUnlock()
248
249 // remove expired keys
250 if len(expiredKeys) > 0 {
251 this.locker.Lock()
252 for _, k := range expiredKeys {
253 delete(this.clientsMap, k)
254 }
255 this.locker.Unlock()
256 }
257
258 // close expired clients
259 if len(expiredClients) > 0 {
260 for _, client := range expiredClients {
261 client.Close()
262 }
263 }
264 }
265}
266
267// 支持PROXY Protocol
268func (this *HTTPClientPool) handlePROXYProtocol(conn net.Conn, req *HTTPRequest, proxyProtocol *serverconfigs.ProxyProtocolConfig) error {

Callers 1

NewHTTPClientPoolFunction · 0.80

Calls 9

NowFunction · 0.92
UnixMethod · 0.80
RLockMethod · 0.80
AccessTimeMethod · 0.80
IsProxyProtocolMethod · 0.80
RUnlockMethod · 0.80
CloseMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected