mirror of
https://github.com/kernelkit/infix.git
synced 2026-08-04 14:43:01 +02:00
test: netns: Avoid infinite hangs on exceptions in .call()s
If the callable threw an exception, then the process running inside the netns would exit before sending back a value on the tx pipe, which meant that `rx.recv()` would hang in the original process. Make sure that we catch any exceptions, and send that instead of the result over the pipe in those scenarios. Then in the original process, re-raise the exception.
This commit is contained in:
+13
-1
@@ -139,6 +139,10 @@ class IsolatedMacVlans:
|
||||
f"{a[0]:02x}:{a[1]:02x}:{a[2]:02x}:" + \
|
||||
f"{a[3]:02x}:{a[4]:02x}:{a[5]:02x}"
|
||||
|
||||
class CallException:
|
||||
def __init__(self, inner):
|
||||
self.inner = inner
|
||||
|
||||
def _ns_call(self, fn, tx):
|
||||
pid = self.sleeper.pid
|
||||
|
||||
@@ -150,7 +154,12 @@ class IsolatedMacVlans:
|
||||
setns(nns, CLONE_NEWNET)
|
||||
os.close(nns)
|
||||
|
||||
tx.send(fn())
|
||||
try:
|
||||
ret = fn()
|
||||
except Exception as e:
|
||||
ret = IsolatedMacVlans.CallException(e)
|
||||
|
||||
tx.send(ret)
|
||||
tx.close()
|
||||
|
||||
def call(self, fn):
|
||||
@@ -161,6 +170,9 @@ class IsolatedMacVlans:
|
||||
ret = rx.recv()
|
||||
rx.close()
|
||||
proc.join()
|
||||
|
||||
if type(ret) == IsolatedMacVlans.CallException:
|
||||
raise ret.inner
|
||||
return ret
|
||||
|
||||
def _mangle_subprocess_args(self, args, kwargs):
|
||||
|
||||
Reference in New Issue
Block a user