Open bostonrwalker opened 2 years ago
Our library doesn't officially support running multiple nodes in a single process if that's what you're doing. We can consider changing that in the future but that's likely pretty far down the road.
In the meantime can you run these nodes as separate processes?
Thanks for the reply. This code should run the nodes in separate processes, although I'm not entirely sure how Python multiprocessing interacts with native libraries.
Hmm. Interesting. The only thing I can think of is that its usage of the Python GIL isn't appropriate for use with multiprocessing import Process
. I've tested this many times running a client and server on the same machine but when I do I'd independently start multiple python processes. Try that if you haven't.
Regardless I'd still consider this a bug so I will keep this ticket open.
Thanks. I tried importing libzt locally within the listen() callable (as per https://stackoverflow.com/questions/34860875/tkinter-spinbox-and-multiprocessing-causes-mac-segfault) and the segfaults are less frequent now.
def _listen(_queue: Queue, net_id: int, port: int):
"""Asynchronous server process"""
# Local import within process
import libzt
...
I will keep chasing the segfaults and try and provide another replicating example if I can.
Incidentally, this exact same code fails frequently with ConnectionAbortedError. From what I can tell, this happens whenever the connection process takes more than 60 seconds. Two issues:
Thank you. I'll take a closer look at these tickets next week.
Update: I was able to make two observations:
This leads me to think there is a race condition and it is present in the error handling code. I had a look at handle_error()
and it looks like it is calling errno()
which is not thread-safe. I put a delay at the top of this function and it seems to fix the issue:
def handle_error(err):
"""Convert libzt error code to exception"""
time.sleep(0.1)
...
So I suspect the issue is within the errno()
function.
I am experiencing segmentation faults when attempting to run simultaneous client/server processes in Python on an M1 Mac.
This issue only happens when running a simultaneous client and server, i.e. the issue does not occur when running multiple server processes at the same time with no client process.
libzt version 1.4.2 Python version: 3.7.9 Architecture: M1 Mac
Here is the crash dump:
Here is a code snippet to reproduce: