-
Type: Improvement
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
None
CDRIVER-2857 is going to introduce a mongoc_client_reset() function that can be called after forking. This function will allow libmongoc to ensure a few things:
- Existing connections are dropped, while SDAM topology is preserved
- Existing cursors will no longer interact with the server (e.g. getMore or killCursors will not be invoked in the child). We'll rely on libmongoc to raise errors if a child attempts to interact the server via a parent's cursor; however, there is probably no harm in allowing iteration of results already stored in the local batch.
- Existing sessions IDs from the parent won't be reused in the client, and endSessions will not be invoked for those lsids. We'll rely on libmongoc to raise errors if a mongoc_client_session_t is re-used in a child process.
To leverage mongoc_client_reset(), the PHP driver will need a few changes:
- Record the current PID when a Manager, Session, or Client object is created
- During each free_object handler (i.e. destructor), check whether the current PID differs. If so, call mongoc_client_reset() on the associated mongoc_client_t before proceeding to call the appropriate libmongoc "destroy" function.
- In order to avoid calling mongoc_client_reset() redundantly, the PHP driver should include some logic to determine if it has already been invoked for a given PID.
In a previous version of this issue (when it only pertained to children not killing cursors created in the parent), we highlighted differences from PHPC-912. With this change, the PHP driver may actually allow children to destroy clients provided we check PIDs and reset accordingly before doing so. This would allow the driver to no longer leak memory, even though that was never a serious concern due to client destruction only happening when the process is shutting down.
- depends on
-
CDRIVER-3116 Do not disconnect sockets in mongoc_client_reset()
- Closed
-
CDRIVER-2857 Provide a reset method to be called on clients after forking
- Closed
-
PHPC-1364 Upgrade libmongoc to 1.14.0
- Closed
- is depended on by
-
PHPC-1284 Driver session pools must be cleared after forking
- Closed
- is related to
-
PHPC-912 Child processes should not destroy clients created by parent processes
- Closed
- related to
-
PHPC-1526 Forking session test has intermittent failures on SHARDED_CLUSTER_RS
- Closed
-
PHPC-1529 Reset libmongocrypt's key vault client after forking
- Closed
-
CDRIVER-3438 Destroy exhaust cursor socket in mongoc_cursor_destroy regardless of client generation
- Closed
-
PHPC-1522 Allow child processes to destroy parent clients after resetting
- Backlog
-
PHPC-1368 Avoid redundant calls to mongoc_client_reset()
- Closed
- links to