[GODRIVER-1214] Cancelling the context associated with a query does not actually cancel the query Created: 02/Aug/19 Updated: 27/Oct/23 Resolved: 05/Aug/19 |
|
| Status: | Closed |
| Project: | Go Driver |
| Component/s: | API |
| Affects Version/s: | 1.0.4 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Matthew Zimmerman | Assignee: | Unassigned |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Linux, Go |
||
| Comments |
| Comment by Kristofer Brandow (Inactive) [ 06/Aug/19 ] | |||||||||||||||||||||||||||||||||||||||||||||||||
|
The MongoDB Wire Protocol does not support the functionality you mentioned, so it would be difficult and buggy to stop the work on the server. Timing out or cancelling operations is something the MongoDB drivers team is working on and you can follow the progress of that specifications via DRIVERS-555.
| |||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Matthew Zimmerman [ 06/Aug/19 ] | |||||||||||||||||||||||||||||||||||||||||||||||||
|
A major point of the context interface is that if the context is cancelled, the work should stop. Since net.Connection.Read() doesn't accept a context, google wrote their httpDo() method like this: https://blog.golang.org/context#TOC_3.3. With this implementation, the server would still be working, but at least the client could exit and continue good work. I'm not familiar with the mongodb wire protocol, but I would imagine that it receives the opid from the server when a command is run such that when requests/responses are combined together over the same network stream that the client and server can determine which request goes with which response. If that's the case, then the client would have an opid that it could cancel the work on the server when the context is cancelled. Thus, the server would return an error on the net.Conn.Read() call and the original thread would be cancelled as well as the work on the server. I found your response to be uninspiring and unhelpful and untrue. The net.Dial methods do accept a context; but they only recognize it for the connection attempt; once the network socket is established. You are correct in that the cancellation of the context is not recognized for the duration of the connection. | |||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jeffrey Yemin [ 05/Aug/19 ] | |||||||||||||||||||||||||||||||||||||||||||||||||
|
The driver can't really do what you're asking because Go's net library does not take a context in any of the functions that do I/O. Therefore cancelling the context has no effect once we're waiting for I/O. | |||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Matthew Zimmerman [ 02/Aug/19 ] | |||||||||||||||||||||||||||||||||||||||||||||||||
|
This quits at ~20 seconds. I would expect it to quit at ~5. | |||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Matthew Zimmerman [ 02/Aug/19 ] | |||||||||||||||||||||||||||||||||||||||||||||||||
|