Skip to content

Commit

Permalink
Reduce number of logs around connection acquisition timeouts (#498)
Browse files Browse the repository at this point in the history
Co-authored-by: Rouven Bauer <rouven.bauer@neo4j.com>
  • Loading branch information
fbiville and robsdedude authored May 24, 2023
1 parent 29a9396 commit 4f29cdc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion neo4j/driver_with_context_examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
)

var myDriver DriverWithContext
var ctx context.Context
var ctx = context.Background()

func ExampleExecuteQuery() {
query := "RETURN $value AS val"
Expand Down
19 changes: 9 additions & 10 deletions neo4j/session_with_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func newSessionWithContext(
now *func() time.Time,
) *sessionWithContext {
logId := log.NewId()
logger.Debugf(log.Session, logId, "Created with context")
logger.Debugf(log.Session, logId, "Created")

fetchSize := config.FetchSize
if sessConfig.FetchSize != FetchDefault {
Expand Down Expand Up @@ -507,18 +507,17 @@ func (s *sessionWithContext) getServers(mode idb.AccessMode) func(context.Contex
}

func (s *sessionWithContext) getConnection(ctx context.Context, mode idb.AccessMode, livenessCheckThreshold time.Duration) (idb.Connection, error) {
if s.driverConfig.ConnectionAcquisitionTimeout > 0 {
timeout := s.driverConfig.ConnectionAcquisitionTimeout
if timeout > 0 {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(ctx, s.driverConfig.ConnectionAcquisitionTimeout)
ctx, cancel = context.WithTimeout(ctx, timeout)
if cancel != nil {
defer cancel()
}
s.log.Debugf(log.Session, s.logId, "connection acquisition timeout is: %s",
s.driverConfig.ConnectionAcquisitionTimeout.String())
if deadline, ok := ctx.Deadline(); ok {
s.log.Debugf(log.Session, s.logId, "connection acquisition resolved deadline is: %s",
deadline.String())
}
deadline, _ := ctx.Deadline()
s.log.Debugf(log.Session, s.logId, "connection acquisition timeout is %s, resolved deadline is: %s", timeout, deadline)
} else if deadline, ok := ctx.Deadline(); ok {
s.log.Debugf(log.Session, s.logId, "connection acquisition user-provided deadline is: %s", deadline)
}

if err := s.resolveHomeDatabase(ctx); err != nil {
Expand All @@ -532,7 +531,7 @@ func (s *sessionWithContext) getConnection(ctx context.Context, mode idb.AccessM
conn, err := s.pool.Borrow(
ctx,
s.getServers(mode),
s.driverConfig.ConnectionAcquisitionTimeout != 0,
timeout != 0,
s.config.BoltLogger,
livenessCheckThreshold,
s.auth)
Expand Down
2 changes: 1 addition & 1 deletion neo4j/session_with_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ func TestSession(outer *testing.T) {
pool.ReturnHook = func() {
poolReturnsCalls++
}
tx, err := session.BeginTransaction(ctx)
tx, err := session.BeginTransaction(context.Background())

AssertNoError(t, err)
_, err = tx.Run(ctx, "RETURN 42", nil)
Expand Down

0 comments on commit 4f29cdc

Please sign in to comment.