When we run out of connections, handle an extra one synchronously
This commit is contained in:
parent
d996e3424d
commit
da69583bd2
|
@ -369,14 +369,14 @@ func (proxy *Proxy) udpListener(clientPc *net.UDPConn) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
packet := buffer[:length]
|
packet := buffer[:length]
|
||||||
|
if !proxy.clientsCountInc() {
|
||||||
|
dlog.Warnf("Too many incoming connections (max=%d)", proxy.maxClients)
|
||||||
|
proxy.processIncomingQuery("udp", proxy.mainProto, packet, &clientAddr, clientPc, time.Now()) // handle synchronously
|
||||||
|
continue
|
||||||
|
}
|
||||||
go func() {
|
go func() {
|
||||||
if !proxy.clientsCountInc() {
|
|
||||||
dlog.Warnf("Too many incoming connections (max=%d)", proxy.maxClients)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer proxy.clientsCountDec()
|
defer proxy.clientsCountDec()
|
||||||
start := time.Now()
|
proxy.processIncomingQuery("udp", proxy.mainProto, packet, &clientAddr, clientPc, time.Now())
|
||||||
proxy.processIncomingQuery("udp", proxy.mainProto, packet, &clientAddr, clientPc, start)
|
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -388,12 +388,13 @@ func (proxy *Proxy) tcpListener(acceptPc *net.TCPListener) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if !proxy.clientsCountInc() {
|
||||||
|
dlog.Warnf("Too many incoming connections (max=%d)", proxy.maxClients)
|
||||||
|
clientPc.Close()
|
||||||
|
continue
|
||||||
|
}
|
||||||
go func() {
|
go func() {
|
||||||
defer clientPc.Close()
|
defer clientPc.Close()
|
||||||
if !proxy.clientsCountInc() {
|
|
||||||
dlog.Warnf("Too many incoming connections (max=%d)", proxy.maxClients)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer proxy.clientsCountDec()
|
defer proxy.clientsCountDec()
|
||||||
if err := clientPc.SetDeadline(time.Now().Add(proxy.timeout)); err != nil {
|
if err := clientPc.SetDeadline(time.Now().Add(proxy.timeout)); err != nil {
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue