neo4j / neo4j-go-driver

Neo4j Bolt Driver for Go
Apache License 2.0
482 stars 68 forks source link

[BUG]: (neo4j.SessionWithContext).ExecuteRead is not aborting when the context is canceled #545

Closed svyatoslavratov closed 8 months ago

svyatoslavratov commented 8 months ago

The expected behavior of the ExecuteRead function on context cancelation is the same, to Run function

ctx, cancel := context.WithTimeout(ctx.Background(), time.Second)
_, err := session.ExecuteRead(ctx, ...) // NOT aborting when ctx is canceled
fmt.Println(err) // TransactionExecutionLimit: Timeout after 6 attempts, last error: could not acquire router lock in time when getting routing table
ctx, cancel := context.WithTimeout(ctx.Background(), time.Second)
_, err := session.Run(ctx, ...) // aborting when ctx is canceled
fmt.Println(err) // Reading from connection has been canceled: context canceled

for state.Continue() contain a check for context timeout: https://github.com/neo4j/neo4j-go-driver/blob/5.0/neo4j/session_with_context.go#L427

Maybe solution:

for state.Continue() {
        select {
        case <-ctx.Done():
            return nil, fmt.Errorf("ExecuteTransaction error: %s", ctx.Err())
        default:
            if hasCompleted, result := s.executeTransactionFunction(ctx, mode, config, &state, work, blockingTxBegin, api); hasCompleted {
            return result, nil
        }
        }
}

Neo4j Version: 5.1.0 Community Neo4j Mode: Single instance Driver version: Go driver 5.4.0 Operating System: macOS 14.0.0

StephenCathcart commented 8 months ago

Hi @svyatoslavratov, thank you for highlighting this issue. I'll do some testing on my end to understand the underlying cause. It's possible that the error is surfacing differently, but the canceled context is still considered.

Could you confirm if this behavior persists in the latest version of the driver?

svyatoslavratov commented 8 months ago

@StephenCathcart in new version (5.14.0) this issue is resolved. Thanks you :) can be closed