Skip to content

Commit 0c67be4

Browse files
committed
requests, client, conn: close all rpc signal channels if handler goroutine for client exits
node/test, node/bench: make idle timeout test less flaky by allowing for io.EOF instead of noise.ErrMessageTooLarge, and remove parallelism for rpc benchmark id/test: make test less flaky
1 parent 8207950 commit 0c67be4

File tree

6 files changed

+25
-5
lines changed

6 files changed

+25
-5
lines changed

client.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@ func (c *Client) request(ctx context.Context, data []byte) (message, error) {
284284

285285
select {
286286
case msg = <-ch:
287+
if msg.nonce == 0 {
288+
return message{}, io.EOF
289+
}
287290
case <-ctx.Done():
288291
return message{}, ctx.Err()
289292
}
@@ -470,6 +473,7 @@ func (c *Client) handshake(ctx context.Context) {
470473

471474
func (c *Client) handleLoop() {
472475
defer close(c.handlerDone)
476+
defer c.requests.close()
473477

474478
for {
475479
msg, err := c.recv(context.Background())

error.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@ package noise
33
import "errors"
44

55
var (
6+
// ErrMessageTooLarge is reported by a client when it receives a message from a peer that exceeds the max
7+
// receivable message size limit configured on a node.
68
ErrMessageTooLarge = errors.New("msg from peer is too large")
79
)

id_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ func TestID_String(t *testing.T) {
1515
t.Parallel()
1616

1717
f := func(publicKey noise.PublicKey, host net.IP, port uint16) bool {
18-
h := host.String() // Make-shift 'normalizeIP(net.IP)'.
18+
if host.IsLoopback() || host.IsUnspecified() { // Make-shift 'normalizeIP(net.IP)'.
19+
host = nil
20+
}
21+
22+
h := host.String()
1923
if h == "<nil>" {
2024
h = ""
2125
}

map.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,13 @@ func (r *requestMap) findRequest(nonce uint64) chan<- message {
146146

147147
return ch
148148
}
149+
150+
func (r *requestMap) close() {
151+
r.Lock()
152+
defer r.Unlock()
153+
154+
for nonce := range r.entries {
155+
close(r.entries[nonce])
156+
delete(r.entries, nonce)
157+
}
158+
}

node_options.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ func WithNodeMaxOutboundConnections(maxOutboundConnections uint) NodeOption {
4848
}
4949
}
5050

51-
// WithNodeMaxRecvSize sets the max number of bytes a node is willing to receive from a peer. If the limit is ever
52-
// exceeded, the peer is disconnected with an error. Setting this option to zero will disable the limit. By default,
53-
// the max number of bytes a node is willing to receive from a peer is set to 2MB.
51+
// WithNodeMaxRecvMessageSize sets the max number of bytes a node is willing to receive from a peer. If the limit is
52+
// ever exceeded, the peer is disconnected with an error. Setting this option to zero will disable the limit. By
53+
// default, the max number of bytes a node is willing to receive from a peer is set to 2MB.
5454
func WithNodeMaxRecvMessageSize(maxRecvMessageSize uint32) NodeOption {
5555
return func(n *Node) {
5656
n.maxRecvMessageSize = maxRecvMessageSize

node_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ func TestWithNodeMaxRecvMessageSize(t *testing.T) {
371371

372372
client := a.Inbound()[0]
373373
client.WaitUntilClosed()
374-
assert.True(t, errors.Is(client.Error(), noise.ErrMessageTooLarge))
374+
assert.True(t, errors.Is(client.Error(), noise.ErrMessageTooLarge) || errors.Is(client.Error(), io.EOF))
375375
}
376376

377377
func BenchmarkRPC(b *testing.B) {

0 commit comments

Comments
 (0)