Skip to content

Commit d463827

Browse files
committed
Remove read timeout log from critical section
1 parent 23b666f commit d463827

12 files changed

+16
-64
lines changed

neo4j/internal/bolt/bolt3.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,6 @@ func NewBolt3(serverName string, conn net.Conn, logger log.Logger, boltLog log.B
100100
boltMajor: 3,
101101
},
102102
connReadTimeout: -1,
103-
logger: logger,
104-
logName: log.Bolt3,
105103
},
106104
birthDate: now,
107105
idleDate: now,
@@ -207,7 +205,6 @@ func (b *bolt3) Connect(ctx context.Context, minor int, auth map[string]any, use
207205
b.connId = succ.connectionId
208206
connectionLogId := fmt.Sprintf("%s@%s", b.connId, b.serverName)
209207
b.logId = connectionLogId
210-
b.in.logId = connectionLogId
211208
b.in.hyd.logId = connectionLogId
212209
b.out.logId = connectionLogId
213210
b.serverVersion = succ.server

neo4j/internal/bolt/bolt3server_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ package bolt
2222
import (
2323
"context"
2424
"fmt"
25-
"github.com/neo4j/neo4j-go-driver/v5/neo4j/log"
2625
"io"
2726
"net"
2827
"testing"
@@ -93,7 +92,7 @@ func (s *bolt3server) waitForHello() {
9392
}
9493

9594
func (s *bolt3server) receiveMsg() *testStruct {
96-
_, buf, err := dechunkMessage(context.Background(), s.conn, []byte{}, -1, log.Void{}, "", "")
95+
_, buf, err := dechunkMessage(context.Background(), s.conn, []byte{}, -1)
9796
if err != nil {
9897
panic(err)
9998
}

neo4j/internal/bolt/bolt4.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,6 @@ func NewBolt4(serverName string, conn net.Conn, logger log.Logger, boltLog log.B
118118
boltMajor: 4,
119119
},
120120
connReadTimeout: -1,
121-
logger: logger,
122-
logName: log.Bolt4,
123121
},
124122
lastQid: -1,
125123
}
@@ -276,7 +274,6 @@ func (b *bolt4) Connect(ctx context.Context, minor int, auth map[string]any, use
276274
connectionLogId := fmt.Sprintf("%s@%s", b.connId, b.serverName)
277275
b.logId = connectionLogId
278276
b.in.hyd.logId = connectionLogId
279-
b.in.logId = connectionLogId
280277
b.out.logId = connectionLogId
281278

282279
b.initializeReadTimeoutHint(succ.configurationHints)

neo4j/internal/bolt/bolt4server_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ package bolt
2222
import (
2323
"context"
2424
"fmt"
25-
"github.com/neo4j/neo4j-go-driver/v5/neo4j/log"
2625
"io"
2726
"net"
2827
"reflect"
@@ -106,7 +105,7 @@ func (s *bolt4server) waitForHello() map[string]any {
106105
}
107106

108107
func (s *bolt4server) receiveMsg() *testStruct {
109-
_, buf, err := dechunkMessage(context.Background(), s.conn, []byte{}, -1, log.Void{}, "", "")
108+
_, buf, err := dechunkMessage(context.Background(), s.conn, []byte{}, -1)
110109
if err != nil {
111110
panic(err)
112111
}

neo4j/internal/bolt/bolt5.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,6 @@ func NewBolt5(serverName string, conn net.Conn, logger log.Logger, boltLog log.B
118118
useUtc: true,
119119
},
120120
connReadTimeout: -1,
121-
logger: logger,
122-
logName: log.Bolt5,
123121
},
124122
lastQid: -1,
125123
}
@@ -265,7 +263,6 @@ func (b *bolt5) Connect(ctx context.Context, minor int, auth map[string]any, use
265263
connectionLogId := fmt.Sprintf("%s@%s", b.connId, b.serverName)
266264
b.logId = connectionLogId
267265
b.in.hyd.logId = connectionLogId
268-
b.in.logId = connectionLogId
269266
b.out.logId = connectionLogId
270267

271268
b.initializeReadTimeoutHint(succ.configurationHints)

neo4j/internal/bolt/bolt5server_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ package bolt
2222
import (
2323
"context"
2424
"fmt"
25-
"github.com/neo4j/neo4j-go-driver/v5/neo4j/log"
2625
"io"
2726
"net"
2827
"testing"
@@ -96,7 +95,7 @@ func (s *bolt5server) waitForHello() map[string]any {
9695
}
9796

9897
func (s *bolt5server) receiveMsg() *testStruct {
99-
_, buf, err := dechunkMessage(context.Background(), s.conn, []byte{}, -1, log.Void{}, "", "")
98+
_, buf, err := dechunkMessage(context.Background(), s.conn, []byte{}, -1)
10099
if err != nil {
101100
panic(err)
102101
}

neo4j/internal/bolt/chunker_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ package bolt
2222
import (
2323
"bytes"
2424
"context"
25-
"github.com/neo4j/neo4j-go-driver/v5/neo4j/log"
2625
"net"
2726
"testing"
2827

@@ -83,7 +82,7 @@ func TestChunker(ot *testing.T) {
8382

8483
receiveAndAssertMessage := func(t *testing.T, conn net.Conn, expected []byte) {
8584
t.Helper()
86-
_, msg, err := dechunkMessage(context.Background(), conn, []byte{}, -1, log.Void{}, "", "")
85+
_, msg, err := dechunkMessage(context.Background(), conn, []byte{}, -1)
8786
AssertNoError(t, err)
8887
assertSlices(t, msg, expected)
8988
}

neo4j/internal/bolt/dechunker.go

Lines changed: 5 additions & 33 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/v5/neo4j/internal/racing"
26-
"github.com/neo4j/neo4j-go-driver/v5/neo4j/log"
2726
"net"
2827
"time"
2928
)
@@ -34,22 +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-
ctx context.Context,
39-
conn net.Conn,
40-
msgBuf []byte,
41-
readTimeout time.Duration,
42-
logger log.Logger,
43-
logName string,
44-
logId string) ([]byte, []byte, error) {
36+
func dechunkMessage(ctx context.Context, conn net.Conn, msgBuf []byte, readTimeout time.Duration) ([]byte, []byte, error) {
4537

4638
sizeBuf := []byte{0x00, 0x00}
4739
off := 0
4840

4941
reader := rio.NewRacingReader(conn)
5042

5143
for {
52-
updatedCtx, cancelFunc := newContext(ctx, readTimeout, logger, logName, logId)
44+
updatedCtx, cancelFunc := newContext(ctx, readTimeout)
5345
_, err := reader.ReadFull(updatedCtx, sizeBuf)
5446
if err != nil {
5547
return msgBuf, nil, processReadError(err, ctx, readTimeout)
@@ -73,7 +65,7 @@ func dechunkMessage(
7365
msgBuf = newMsgBuf
7466
}
7567
// Read the chunk into buffer
76-
updatedCtx, cancelFunc = newContext(ctx, readTimeout, logger, logName, logId)
68+
updatedCtx, cancelFunc = newContext(ctx, readTimeout)
7769
_, err = reader.ReadFull(updatedCtx, msgBuf[off:(off+chunkSize)])
7870
if err != nil {
7971
return msgBuf, nil, processReadError(err, ctx, readTimeout)
@@ -86,21 +78,9 @@ func dechunkMessage(
8678
}
8779

8880
// newContext computes a new context and cancel function if a readTimeout is set
89-
func newContext(
90-
ctx context.Context,
91-
readTimeout time.Duration,
92-
logger log.Logger,
93-
logName string,
94-
logId string) (context.Context, context.CancelFunc) {
95-
81+
func newContext(ctx context.Context, readTimeout time.Duration) (context.Context, context.CancelFunc) {
9682
if readTimeout >= 0 {
97-
newCtx, cancelFunc := context.WithTimeout(ctx, readTimeout)
98-
logger.Debugf(logName, logId,
99-
"read timeout of %s applied, chunk read deadline is now: %s",
100-
readTimeout.String(),
101-
deadlineOf(newCtx),
102-
)
103-
return newCtx, cancelFunc
83+
return context.WithTimeout(ctx, readTimeout)
10484
}
10585
return ctx, nil
10686
}
@@ -120,11 +100,3 @@ func processReadError(err error, ctx context.Context, readTimeout time.Duration)
120100
}
121101
return err
122102
}
123-
124-
func deadlineOf(ctx context.Context) string {
125-
deadline, hasDeadline := ctx.Deadline()
126-
if !hasDeadline {
127-
return "N/A (no deadline set)"
128-
}
129-
return deadline.String()
130-
}

neo4j/internal/bolt/dechunker_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"bytes"
2424
"context"
2525
"encoding/binary"
26-
"github.com/neo4j/neo4j-go-driver/v5/neo4j/log"
2726
"net"
2827
"reflect"
2928
"testing"
@@ -83,7 +82,7 @@ func TestDechunker(t *testing.T) {
8382
go func() {
8483
AssertWriteSucceeds(t, cli, str.Bytes())
8584
}()
86-
buf, msgBuf, err = dechunkMessage(context.Background(), serv, buf, -1, log.Void{}, "", "")
85+
buf, msgBuf, err = dechunkMessage(context.Background(), serv, buf, -1)
8786
AssertNoError(t, err)
8887
AssertLen(t, msgBuf, int(msg.size))
8988
// Check content of buffer
@@ -123,7 +122,7 @@ func TestDechunkerWithTimeout(ot *testing.T) {
123122
AssertWriteSucceeds(t, cli, []byte{0x00, 0x00})
124123
}()
125124
buffer := make([]byte, 2)
126-
_, _, err := dechunkMessage(context.Background(), serv, buffer, timeout, log.Void{}, "", "")
125+
_, _, err := dechunkMessage(context.Background(), serv, buffer, timeout)
127126
AssertNoError(t, err)
128127
AssertTrue(t, reflect.DeepEqual(buffer, []byte{0xCA, 0xFE}))
129128
})
@@ -132,7 +131,7 @@ func TestDechunkerWithTimeout(ot *testing.T) {
132131
serv, cli := net.Pipe()
133132
defer closePipe(ot, serv, cli)
134133

135-
_, _, err := dechunkMessage(context.Background(), serv, nil, timeout, log.Void{}, "", "")
134+
_, _, err := dechunkMessage(context.Background(), serv, nil, timeout)
136135

137136
AssertError(t, err)
138137
AssertStringContain(t, err.Error(), "context deadline exceeded")
@@ -144,7 +143,7 @@ func TestDechunkerWithTimeout(ot *testing.T) {
144143
ctx, cancelFunc := context.WithTimeout(context.Background(), timeout)
145144
defer cancelFunc()
146145

147-
_, _, err := dechunkMessage(ctx, serv, nil, -1, log.Void{}, "", "")
146+
_, _, err := dechunkMessage(ctx, serv, nil, -1)
148147

149148
AssertError(t, err)
150149
AssertStringContain(t, err.Error(), "context deadline exceeded")

neo4j/internal/bolt/hydratedehydrate_test.go

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

2222
import (
2323
"context"
24-
"github.com/neo4j/neo4j-go-driver/v5/neo4j/log"
2524
"net"
2625
"testing"
2726
"time"
@@ -58,7 +57,7 @@ func TestDehydrateHydrate(ot *testing.T) {
5857
go func() {
5958
out.send(context.Background(), cli)
6059
}()
61-
_, byts, err := dechunkMessage(context.Background(), serv, []byte{}, -1, log.Void{}, "", "")
60+
_, byts, err := dechunkMessage(context.Background(), serv, []byte{}, -1)
6261
if err != nil {
6362
t.Fatal(err)
6463
}

0 commit comments

Comments
 (0)