[GODRIVER-1076] Watching a ChangeStream doesn't handle Disconnect/Reconnect Created: 21/May/19 Updated: 27/Oct/23 Resolved: 31/May/19 |
|
| Status: | Closed |
| Project: | Go Driver |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Andreas Schneider | Assignee: | Divjot Arora (Inactive) |
| Resolution: | Gone away | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
Using the following code
|
| Comments |
| Comment by Andreas Schneider [ 28/May/19 ] |
|
I guess I have to pull this back. I'm no longer able to reproduce the described behavior on driver version 1.0.2. Either something changed or I had other circumstances. However it now seems to properly return even if the context has no timeout but the server connection times out. That way I can properly reconnect. Also if the server restarts quick enough, the change stream just resumes. So it behaves exactly as I said it should - no idea why it did not before. Sorry for the trouble. |
| Comment by Andreas Schneider [ 26/May/19 ] |
|
The events would not be generated by this code. I'm simply listening to everything in the Change Stream. So whenever some other process modifies the collection, I get an event. The problem is basically what you said: the code will loop until the given context times out. What if I don't specify a timeout because I want to listen endlessly? The program in question needs to react to changes in the collection, so I listen in an endless loop. When the connection to MongoDB is interrupted (network issue, server offline, whatever), the method cs.Next(ctx) keeps blocking. That is useful in the regard, that the context should control the lifetime. However due to the reconnect to MongoDB, that call NEVER unblocks, since the change stream apparently is not re-setup after reconnect (new session I guess)? So IMO either the changestream should be reestablished on reconnect or the cs.Next() call should exit with return value false and an error set to indicate, that the connection was lost. Currently the Go driver offers me no way to deal with reconnects. |
| Comment by Divjot Arora (Inactive) [ 24/May/19 ] |
|
aksdb Can you provide more information about where the events are being generated? The linked code wouldn't generate any events and the driver's change stream code will loop until the given context times out or an event is returned from the server. |