Skip to content

Commit

Permalink
pool: Cleanup client read error logging.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
davecgh committed Sep 15, 2023
1 parent b8110aa commit 64250f3
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions pool/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 64250f3

Please sign in to comment.