1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2025-12-17 14:37:02 +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:
Alberto Bertogli
2016-10-10 10:38:38 +01:00
parent aa0486b54e
commit 008cd98e39

View File

@@ -474,6 +474,7 @@ func (c *Conn) Handle() {
var cmd, params string
var err error
var errCount int
loop:
for {
@@ -538,9 +539,17 @@ loop:
if code > 0 {
c.tr.Debugf("<- %d %s", code, msg)
// Be verbose about errors, to help troubleshooting.
if code >= 400 {
// Be verbose about errors, to help troubleshooting.
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)