zbentley opened a new issue #11953:
URL: https://github.com/apache/pulsar/issues/11953


   **Describe the bug**
   If I `fork()` with a connected Pulsar C++ client instance, the child process 
ends up having a few issues:
   - On garbage collection of the client instance in the child process, `abort` 
is called: `libc++abi: terminating with uncaught exception of type 
std::__1::system_error: thread::detach failed: No such process`
   - If I explicitly call `shutdown` on the client instance in the child 
process, `abort` is called: `thread::detach failed: No such process`
   - If I call `close` on the client instance in the child process, the call 
blocks indefinitely. 
   
   
   **To Reproduce**
   1. Ensure Pulsar is running (I used master as of this writing, 9/7/2021).
   2. Run the following snippet: 
   ```python
   import os
   import pulsar
   
   def main():
       cl = pulsar.Client(
           'pulsar://127.0.0.1:6650',
           operation_timeout_seconds=1,
           connection_timeout_ms=1000,
       )
       prod = cl.create_producer('foobar', send_timeout_millis=1000)
       prod.send(b'1')
       pid = os.fork()
       if pid == 0:  # Child
           print("Child exiting")
       else:  # Parent
           prod.send(b'2')
           os.wait()
           prod.send(b'3')
           print("Parent exiting")
   
   
   if __name__ == '__main__':
       main()
   
   ```
   3. Observe that `abort` is called when the child process shuts down.
   4. Run the following snippet:
   ```python
   import os
   import pulsar
   
   def main():
       cl = pulsar.Client(
           'pulsar://127.0.0.1:6650',
           operation_timeout_seconds=1,
           connection_timeout_ms=1000,
       )
       prod = cl.create_producer('foobar', send_timeout_millis=1000)
       prod.send(b'1')
       pid = os.fork()
       if pid == 0:  # Child
           cl._client.shutdown()
           print("Child exiting")
   
   
   if __name__ == '__main__':
       main()
   
   ```
   6. Observe that a `RuntimeError` is raised.
   7. Run the following snippet:
   ```python
   import os
   import pulsar
   
   def main():
       cl = pulsar.Client(
           'pulsar://127.0.0.1:6650',
           operation_timeout_seconds=1,
           connection_timeout_ms=1000,
       )
       prod = cl.create_producer('foobar', send_timeout_millis=1000)
       prod.send(b'1')
       pid = os.fork()
       if pid == 0:  # Child
           cl.close()
           print("Child exiting")
       else:
           os.wait()
   
   if __name__ == '__main__':
       main()
   ```
   8. Observe that the program blocks for longer than any specified timeouts.
   
   
   **Expected behavior**
   1. Snippet 1 should exit successfully without error.
   2. Snippet 2 should fail with `AlreadyClosed` or some equivalent error 
indicating that the client is no longer usable and needs to be destroyed and 
recreated by the user.
   3. Snippet 3 should either succeed, or should raise `AlreadyClosed` or 
equivalent from the call to `close`.
   
   **Desktop (please complete the following information):**
    - OS: MacOS 10.11
    - Python Pulsar client built against master at commit `d86db3f4ec`
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to