Skip to content

Commit 23b666f

Browse files
committed
Warn of the impact of early context terminations
Since 78c1c75, an early context termination results in the active connection's socket to be closed. This potentially valid connection will be marked as dead and will not be a candidate for future reuse. Moreover, the cleanup of idle connections that are too old may not even occur if the context has terminated. This results in the pool gradually filling up with potentially bad connections.
1 parent 78c1c75 commit 23b666f

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

neo4j/driver_with_context.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ type DriverWithContext interface {
7272
// VerifyConnectivity checks that the driver can connect to a remote server or cluster by
7373
// establishing a network connection with the remote. Returns nil if successful
7474
// or error describing the problem.
75+
// Contexts terminating too early negatively affect connection pooling and degrade the driver performance.
7576
VerifyConnectivity(ctx context.Context) error
7677
// Close the driver and all underlying connections
7778
Close(ctx context.Context) error
@@ -81,6 +82,7 @@ type DriverWithContext interface {
8182
IsEncrypted() bool
8283
// GetServerInfo attempts to obtain server information from the target Neo4j
8384
// deployment
85+
// Contexts terminating too early negatively affect connection pooling and degrade the driver performance.
8486
GetServerInfo(ctx context.Context) (ServerInfo, error)
8587
}
8688

@@ -440,6 +442,8 @@ func (d *driverWithContext) Close(ctx context.Context) error {
440442
// functions.
441443
// Since ResultTransformer implementations are inherently stateful, the function must return a new ResultTransformer
442444
// instance every time it is called.
445+
//
446+
// Contexts terminating too early negatively affect connection pooling and degrade the driver performance.
443447
func ExecuteQuery[T any](
444448
ctx context.Context,
445449
driver DriverWithContext,

neo4j/session_with_context.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,21 @@ type SessionWithContext interface {
5454
LastBookmarks() Bookmarks
5555
lastBookmark() string
5656
// BeginTransaction starts a new explicit transaction on this session
57+
// Contexts terminating too early negatively affect connection pooling and degrade the driver performance.
5758
BeginTransaction(ctx context.Context, configurers ...func(*TransactionConfig)) (ExplicitTransaction, error)
5859
// ExecuteRead executes the given unit of work in a AccessModeRead transaction with
5960
// retry logic in place
61+
// Contexts terminating too early negatively affect connection pooling and degrade the driver performance.
6062
ExecuteRead(ctx context.Context, work ManagedTransactionWork, configurers ...func(*TransactionConfig)) (any, error)
6163
// ExecuteWrite executes the given unit of work in a AccessModeWrite transaction with
6264
// retry logic in place
65+
// Contexts terminating too early negatively affect connection pooling and degrade the driver performance.
6366
ExecuteWrite(ctx context.Context, work ManagedTransactionWork, configurers ...func(*TransactionConfig)) (any, error)
6467
// Run executes an auto-commit statement and returns a result
68+
// Contexts terminating too early negatively affect connection pooling and degrade the driver performance.
6569
Run(ctx context.Context, cypher string, params map[string]any, configurers ...func(*TransactionConfig)) (ResultWithContext, error)
6670
// Close closes any open resources and marks this session as unusable
71+
// Contexts terminating too early negatively affect connection pooling and degrade the driver performance.
6772
Close(ctx context.Context) error
6873

6974
legacy() Session

neo4j/transaction_with_context.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,17 @@ type ManagedTransaction interface {
3535
// ExplicitTransaction represents a transaction in the Neo4j database
3636
type ExplicitTransaction interface {
3737
// Run executes a statement on this transaction and returns a result
38+
// Contexts terminating too early negatively affect connection pooling and degrade the driver performance.
3839
Run(ctx context.Context, cypher string, params map[string]any) (ResultWithContext, error)
3940
// Commit commits the transaction
41+
// Contexts terminating too early negatively affect connection pooling and degrade the driver performance.
4042
Commit(ctx context.Context) error
4143
// Rollback rolls back the transaction
44+
// Contexts terminating too early negatively affect connection pooling and degrade the driver performance.
4245
Rollback(ctx context.Context) error
4346
// Close rolls back the actual transaction if it's not already committed/rolled back
4447
// and closes all resources associated with this transaction
48+
// Contexts terminating too early negatively affect connection pooling and degrade the driver performance.
4549
Close(ctx context.Context) error
4650

4751
// legacy returns the non-cancelling, legacy variant of this ExplicitTransaction type

0 commit comments

Comments
 (0)