Skip to content

ZMQ sockets (zsock_t) do not work in child process after fork #2038

Closed
@santupari

Description

@santupari

Hi All,

We are observing an issue where in sockets created in child process do not work after forking.
Below is the sequence of code and I have also attached test code that reproduces issue and as well as working code:

  1. Our design has a server which listens to multiple clients and responds
  2. Clients uses wrapper API (example : test_tx_rx()) that exchanges messages with server
  3. the issue observed when a client calls test_tx_rx() from parent and then fork and if you call test_tx_rx() from child it fails to communicate with server
  4. The fix is to call zsys_shutdown() from child to clean up all initialization done by parent and assume that ZSYS is already initialized. However, as part of this fix we also noticed that there is a mutex that should be re-initialized to avoid deadlock. Hence, we are also attaching a patch that defines new API for re-initializing the mutex.

Please let us know if the patch is valid or how to avoid deadlock in case if the parents threads are accessing the mutex at the same when child is clearing mutex in zsys_shutdown().

Thanks,
Santosh Bidaralli

zsys_patch_wtih_test_code.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions