From 008cd98e398ae4b8ddbd489c3b05ee3744435ecd Mon Sep 17 00:00:00 2001 From: Alberto Bertogli Date: Mon, 10 Oct 2016 10:38:38 +0100 Subject: [PATCH] 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. --- chasquid.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/chasquid.go b/chasquid.go index a747bc6..e7bb41f 100644 --- a/chasquid.go +++ b/chasquid.go @@ -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)