Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-2049

Do not shutdown() sockets created by other processes

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.7.0
    • Affects Version/s: 1.6.0
    • Component/s: libmongoc, network
    • None

      In PHPC-912, a user encountered a situation where a forked child process closed a server connection that was still in use by the parent process. Since the PHP driver persists mongoc_client_t objects in a hash table, this table was copied by the child process and then destroyed when the child process exited while the parent was still alive. Upon destruction, the PHP driver attempts to free any persisted clients with mongoc_client_destroy(), which ultimately calls mongoc_socket_close() for each socket. Therein, shutdown() is called on each file descriptor. I propose that shutdown() only be called if the socket was created by the same PID. close() can always be called, since the operating system will handle reference counting on any shared file descriptors.

      We already plan to associate mongoc_client_t objects with a file descriptor in the PHP driver, to avoid a child process utilizing an existing mongoc_client_t created by a parent process (PHPC-913); however, we have no mechanism to destroy a mongoc_client_t and free memory without also unconditionally triggering shutdown() for each of its sockets. AFAICT, the only alternative would be for the PHP driver to leak mongoc_client_t objects created by other processes, which seems sloppy but may be excusable since this cleanup is happening as the PHP process terminates.

            Assignee:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Reporter:
            jmikola@mongodb.com Jeremy Mikola
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: