[GODRIVER-1662] Respect context cancellation once an operation has been dispatched Created: 22/Jun/20  Updated: 28/Oct/23  Resolved: 13/Aug/20

Status: Closed
Project: Go Driver
Component/s: None
Affects Version/s: None
Fix Version/s: 1.5.0

Type: Improvement Priority: Major - P3
Reporter: Divjot Arora (Inactive) Assignee: Divjot Arora (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Problem/Incident
Related

 Description   

Because the net.Conn.Read and net.Conn.Write functions don't take a context, the driver doesn't respect context cancellation once an operation has been dispatched to the server. This creates confusing semantics for users who expect blocking work to stop on context cancellation. Some ideas/thoughts I've had about this:

  1. We can spin up a separate goroutine in ReadWireMessage/WriteWireMessage to listen for ctx.Done and close the connection or set it's read/write deadline to a previous time. We'll need to ensure we return context.Cancelled rather than the net.Error from the read/write call so the server pool isn't unnecessarily cleared.
  2. The first suggestion can cause connection churn. If users are using context cancellation to signal some sort of shutdown, this is probably fine. If it's being used to implement things like application-level hedging, unnecessarily invalidating connections could cause issues. The only idea I have for doing is cleanly is to send an out of band killOp command, but this requires checking out another connection from the pool (or making a dedicated one?) and also first running currOp to get the operation ID. This might not be acceptable because we'd be doing two blocking round trips after the context has been cancelled.
  3. Killing the session associated with the op works too and is only one roundtrip, but I've been told that it's a relatively expensive operation because sessions have a lot of server-side state (e.g. retryable writes, transactions, etc). 


 Comments   
Comment by Githook User [ 13/Aug/20 ]

Author:

{'name': 'Divjot Arora', 'email': 'divjot.arora@10gen.com', 'username': 'divjotarora'}

Message: GODRIVER-1662 Respect context.Cancellation for network operations (#473)
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/96efc632cadffc55ba0fd8d046a1ad9fb1130a21

Comment by Divjot Arora (Inactive) [ 31/Jul/20 ]

https://github.com/mongodb/mongo-go-driver/pull/473

Generated at Thu Feb 08 08:36:52 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.