mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-18 14:47:03 +00:00
chasquid: Break connections after 10 errors
If a connection has accumulated 10 errors, it's very likely that something has gone significantly wrong, or they're just probing/abusing the service. This patch makes chasquid break the connection after 10 errors. The number is arbitrary, we may adjust it later.
This commit is contained in:
11
chasquid.go
11
chasquid.go
@@ -474,6 +474,7 @@ func (c *Conn) Handle() {
|
|||||||
|
|
||||||
var cmd, params string
|
var cmd, params string
|
||||||
var err error
|
var err error
|
||||||
|
var errCount int
|
||||||
|
|
||||||
loop:
|
loop:
|
||||||
for {
|
for {
|
||||||
@@ -538,9 +539,17 @@ loop:
|
|||||||
if code > 0 {
|
if code > 0 {
|
||||||
c.tr.Debugf("<- %d %s", code, msg)
|
c.tr.Debugf("<- %d %s", code, msg)
|
||||||
|
|
||||||
// Be verbose about errors, to help troubleshooting.
|
|
||||||
if code >= 400 {
|
if code >= 400 {
|
||||||
|
// Be verbose about errors, to help troubleshooting.
|
||||||
c.tr.Errorf("%s failed: %d %s", cmd, code, msg)
|
c.tr.Errorf("%s failed: %d %s", cmd, code, msg)
|
||||||
|
|
||||||
|
errCount++
|
||||||
|
if errCount > 10 {
|
||||||
|
// https://tools.ietf.org/html/rfc5321#section-4.3.2
|
||||||
|
c.tr.Errorf("too many errors, breaking connection")
|
||||||
|
c.writeResponse(421, "too many errors, bye")
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.writeResponse(code, msg)
|
err = c.writeResponse(code, msg)
|
||||||
|
|||||||
Reference in New Issue
Block a user