Skip to content

Commit 07b9555

Browse files
committed
Remove read timeout log from critical section
1 parent 2476aa2 commit 07b9555

File tree

10 files changed

+14
-53
lines changed

10 files changed

+14
-53
lines changed

neo4j/internal/bolt/bolt3.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ func NewBolt3(serverName string, conn net.Conn, logger log.Logger, boltLog log.B
9797
boltLogger: boltLog,
9898
},
9999
connReadTimeout: -1,
100-
logger: logger,
101-
logName: log.Bolt3,
102100
},
103101
birthDate: time.Now(),
104102
log: logger,
@@ -199,7 +197,6 @@ func (b *bolt3) connect(minor int, auth map[string]interface{}, userAgent string
199197
b.connId = succ.connectionId
200198
connectionLogId := fmt.Sprintf("%s@%s", b.connId, b.serverName)
201199
b.logId = connectionLogId
202-
b.in.logId = connectionLogId
203200
b.in.hyd.logId = connectionLogId
204201
b.out.logId = connectionLogId
205202
b.serverVersion = succ.server

neo4j/internal/bolt/bolt3server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func (s *bolt3server) waitForHello() {
9191
}
9292

9393
func (s *bolt3server) receiveMsg() *testStruct {
94-
_, buf, err := dechunkMessage(s.conn, []byte{}, -1, nil, "", "")
94+
_, buf, err := dechunkMessage(s.conn, []byte{}, -1)
9595
if err != nil {
9696
panic(err)
9797
}

neo4j/internal/bolt/bolt4.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,6 @@ func NewBolt4(serverName string, conn net.Conn, logger log.Logger, boltLog log.B
114114
boltLogger: boltLog,
115115
},
116116
connReadTimeout: -1,
117-
logger: logger,
118-
logName: log.Bolt4,
119117
},
120118
}
121119
b.out = outgoing{
@@ -271,7 +269,6 @@ func (b *bolt4) connect(minor int, auth map[string]interface{}, userAgent string
271269
connectionLogId := fmt.Sprintf("%s@%s", b.connId, b.serverName)
272270
b.logId = connectionLogId
273271
b.in.hyd.logId = connectionLogId
274-
b.in.logId = connectionLogId
275272
b.out.logId = connectionLogId
276273

277274
b.initializeReadTimeoutHint(succ.configurationHints)

neo4j/internal/bolt/bolt4server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func (s *bolt4server) waitForHello() map[string]interface{} {
104104
}
105105

106106
func (s *bolt4server) receiveMsg() *testStruct {
107-
_, buf, err := dechunkMessage(s.conn, []byte{}, -1, nil, "", "")
107+
_, buf, err := dechunkMessage(s.conn, []byte{}, -1)
108108
if err != nil {
109109
panic(err)
110110
}

neo4j/internal/bolt/chunker_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func TestChunker(ot *testing.T) {
8181

8282
receiveAndAssertMessage := func(t *testing.T, conn net.Conn, expected []byte) {
8383
t.Helper()
84-
_, msg, err := dechunkMessage(conn, []byte{}, -1, nil, "", "")
84+
_, msg, err := dechunkMessage(conn, []byte{}, -1)
8585
AssertNoError(t, err)
8686
assertSlices(t, msg, expected)
8787
}

neo4j/internal/bolt/dechunker.go

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"context"
2424
"encoding/binary"
2525
rio "github.com/neo4j/neo4j-go-driver/v4/neo4j/internal/racingio"
26-
"github.com/neo4j/neo4j-go-driver/v4/neo4j/log"
2726
"net"
2827
"time"
2928
)
@@ -34,21 +33,15 @@ import (
3433
// Reads will race against the provided context ctx
3534
// If the server provides the connection read timeout hint readTimeout, a new context will be created from that timeout
3635
// and the user-provided context ctx before every read
37-
func dechunkMessage(
38-
conn net.Conn,
39-
msgBuf []byte,
40-
readTimeout time.Duration,
41-
logger log.Logger,
42-
logName string,
43-
logId string) ([]byte, []byte, error) {
36+
func dechunkMessage(conn net.Conn, msgBuf []byte, readTimeout time.Duration) ([]byte, []byte, error) {
4437

4538
sizeBuf := []byte{0x00, 0x00}
4639
off := 0
4740

4841
reader := rio.NewRacingReader(conn)
4942

5043
for {
51-
updatedCtx, cancelFunc := newContext(readTimeout, logger, logName, logId)
44+
updatedCtx, cancelFunc := newContext(readTimeout)
5245
_, err := reader.ReadFull(updatedCtx, sizeBuf)
5346
if err != nil {
5447
return msgBuf, nil, err
@@ -72,7 +65,7 @@ func dechunkMessage(
7265
msgBuf = newMsgBuf
7366
}
7467
// Read the chunk into buffer
75-
updatedCtx, cancelFunc = newContext(readTimeout, logger, logName, logId)
68+
updatedCtx, cancelFunc = newContext(readTimeout)
7669
_, err = reader.ReadFull(updatedCtx, msgBuf[off:(off+chunkSize)])
7770
if err != nil {
7871
return msgBuf, nil, err
@@ -85,29 +78,10 @@ func dechunkMessage(
8578
}
8679

8780
// newContext computes a new context and cancel function if a readTimeout is set
88-
func newContext(
89-
readTimeout time.Duration,
90-
logger log.Logger,
91-
logName string,
92-
logId string) (context.Context, context.CancelFunc) {
93-
81+
func newContext(readTimeout time.Duration) (context.Context, context.CancelFunc) {
9482
ctx := context.Background()
9583
if readTimeout >= 0 {
96-
newCtx, cancelFunc := context.WithTimeout(ctx, readTimeout)
97-
logger.Debugf(logName, logId,
98-
"read timeout of %s applied, chunk read deadline is now: %s",
99-
readTimeout.String(),
100-
deadlineOf(newCtx),
101-
)
102-
return newCtx, cancelFunc
84+
return context.WithTimeout(ctx, readTimeout)
10385
}
10486
return ctx, nil
10587
}
106-
107-
func deadlineOf(ctx context.Context) string {
108-
deadline, hasDeadline := ctx.Deadline()
109-
if !hasDeadline {
110-
return "N/A (no deadline set)"
111-
}
112-
return deadline.String()
113-
}

neo4j/internal/bolt/dechunker_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ package bolt
2222
import (
2323
"bytes"
2424
"encoding/binary"
25-
"github.com/neo4j/neo4j-go-driver/v4/neo4j/log"
2625
"net"
2726
"reflect"
2827
"testing"
@@ -82,7 +81,7 @@ func TestDechunker(t *testing.T) {
8281
go func() {
8382
AssertWriteSucceeds(t, cli, str.Bytes())
8483
}()
85-
buf, msgBuf, err = dechunkMessage(serv, buf, -1, nil, "", "")
84+
buf, msgBuf, err = dechunkMessage(serv, buf, -1)
8685
AssertNoError(t, err)
8786
AssertLen(t, msgBuf, int(msg.size))
8887
// Check content of buffer
@@ -122,7 +121,7 @@ func TestDechunkerWithTimeout(ot *testing.T) {
122121
AssertWriteSucceeds(t, cli, []byte{0x00, 0x00})
123122
}()
124123
buffer := make([]byte, 2)
125-
_, _, err := dechunkMessage(serv, buffer, timeout, log.Void{}, "", "")
124+
_, _, err := dechunkMessage(serv, buffer, timeout)
126125
AssertNoError(t, err)
127126
AssertTrue(t, reflect.DeepEqual(buffer, []byte{0xCA, 0xFE}))
128127
})
@@ -131,7 +130,7 @@ func TestDechunkerWithTimeout(ot *testing.T) {
131130
serv, cli := net.Pipe()
132131
defer closePipe(ot, serv, cli)
133132

134-
_, _, err := dechunkMessage(serv, nil, timeout, log.Void{}, "", "")
133+
_, _, err := dechunkMessage(serv, nil, timeout)
135134

136135
AssertError(t, err)
137136
AssertStringContain(t, err.Error(), "context deadline exceeded")

neo4j/internal/bolt/hydratedehydrate_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func TestDehydrateHydrate(ot *testing.T) {
5656
go func() {
5757
out.send(cli)
5858
}()
59-
_, byts, err := dechunkMessage(serv, []byte{}, -1, nil, "", "")
59+
_, byts, err := dechunkMessage(serv, []byte{}, -1)
6060
if err != nil {
6161
t.Fatal(err)
6262
}

neo4j/internal/bolt/incoming.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
package bolt
2121

2222
import (
23-
"github.com/neo4j/neo4j-go-driver/v4/neo4j/log"
2423
"net"
2524
"time"
2625
)
@@ -29,17 +28,12 @@ type incoming struct {
2928
buf []byte // Reused buffer
3029
hyd hydrator
3130
connReadTimeout time.Duration
32-
logger log.Logger
33-
logName string
34-
logId string
3531
}
3632

3733
func (i *incoming) next(rd net.Conn) (interface{}, error) {
38-
// Get next message from transport layer
3934
var err error
4035
var msg []byte
41-
i.buf, msg, err = dechunkMessage(rd, i.buf, i.connReadTimeout, i.logger,
42-
i.logName, i.logId)
36+
i.buf, msg, err = dechunkMessage(rd, i.buf, i.connReadTimeout)
4337
if err != nil {
4438
return nil, err
4539
}

neo4j/internal/bolt/outgoing_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func TestOutgoing(ot *testing.T) {
109109
}()
110110

111111
// Dechunk it
112-
_, byts, err := dechunkMessage(serv, []byte{}, -1, nil, "", "")
112+
_, byts, err := dechunkMessage(serv, []byte{}, -1)
113113
if err != nil {
114114
t.Fatal(err)
115115
}

0 commit comments

Comments
 (0)