From 64250f3db3ccc9f18a39f83f5f9e530bd3b5ba5b Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Fri, 15 Sep 2023 18:37:22 -0500 Subject: [PATCH] pool: Cleanup client read error logging. This switches the code that examines read errors for timeout to use the proper interface from the net package that is designed for that purpose instead of digging into concrete types. It also ensures clients that timeout without ever identifying themselves have their uniquely-assigned extra nonce used as the id instead so the log messages can be attributed to the ip of the offending clients. Finally, it no longer logs an error when an io.EOF is encountered as that is an expected condition when the client disconnects and is not an actual error. --- pool/client.go | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/pool/client.go b/pool/client.go index de2e756a..71c9691a 100644 --- a/pool/client.go +++ b/pool/client.go @@ -183,6 +183,11 @@ func (c *Client) shutdown() { id := c.id c.mtx.RUnlock() + // Connections that never identify will not have an ID set, so use their + // uniquely-assigned extranonce in that case. + if id == "" { + id = c.extraNonce1 + } log.Tracef("%s connection terminated.", id) } @@ -708,27 +713,21 @@ func (c *Client) read() { data, err := c.reader.ReadBytes('\n') if err != nil { if errors.Is(err, io.EOF) { - log.Errorf("%s: EOF", id) - c.cancel() - return - } - var nErr *net.OpError - if !errors.As(err, &nErr) { - log.Errorf("%s: unable to read bytes: %v", id, err) c.cancel() return } - if nErr.Op == "read" && nErr.Net == "tcp" { - switch { - case nErr.Timeout(): - log.Errorf("%s: read timeout: %v", id, err) - case !nErr.Timeout(): - log.Errorf("%s: read error: %v", id, err) + var nErr net.Error + if errors.As(err, &nErr) && nErr.Timeout() { + // Connections that never identify will not have an ID set, so + // use their uniquely-assigned extranonce in that case. + if id == "" { + id = c.extraNonce1 } + log.Errorf("%s: read timeout: %v", id, err) c.cancel() return } - log.Errorf("unable to read bytes: %v %T", err, err) + log.Errorf("%s: unable to read bytes: %v (%[2]T)", id, err) c.cancel() return }