清理不使用的Client
()
| 229 | |
| 230 | // 清理不使用的Client |
| 231 | func (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 |
| 268 | func (this *HTTPClientPool) handlePROXYProtocol(conn net.Conn, req *HTTPRequest, proxyProtocol *serverconfigs.ProxyProtocolConfig) error { |
no test coverage detected