Fix `NSPopen` proxy leaks

pull/8/head
Jack O'Sullivan 5 years ago
parent 3e15f5c7aa
commit 1c3c2ec5d5

@ -324,9 +324,12 @@ class ContainerDHCPManager:
logger.info('[dhcp container] Replacing gateway with %s', dhcp.gateway)
proc = NSPopen(dhcp.netns, ['/sbin/ip', 'route', 'replace', 'default', 'via', str(dhcp.gateway)])
if proc.wait(timeout=1) != 0:
raise NetDhcpError(f'Failed to replace default route; "ip route" command exited with non-zero code %d', \
proc.returncode)
try:
if proc.wait(timeout=1) != 0:
raise NetDhcpError(f'Failed to replace default route; "ip route" command exited with non-zero code %d', \
proc.returncode)
finally:
proc.release()
# TODO: Adding default route with NDB seems to be broken (because of the dst syntax?)
#for route in ndb.routes:
@ -362,6 +365,8 @@ class ContainerDHCPManager:
self.dhcp6.netns)
except Exception as e:
logger.exception(e)
if self.dhcp:
self.dhcp.finish(timeout=1)
def stop(self):
if not self.dhcp:

@ -126,21 +126,23 @@ class DHCPClient:
if self._shutdown_event.is_set():
return
if self.proc.returncode is not None and (not self.once or self.proc.returncode != 0):
raise DHCPClientError(f'udhcpc{self._suffix} exited early with code {self.proc.returncode}')
if self.once:
self.await_ip()
else:
self.proc.terminate()
if self.proc.wait(timeout=timeout) != 0:
raise DHCPClientError(f'udhcpc{self._suffix} exited with non-zero exit code {self.proc.returncode}')
if self.netns:
self.proc.release()
self._shutdown_event.set()
self._event_thread.join()
self._event_queue.close()
self._event_queue.unlink()
try:
if self.proc.returncode is not None and (not self.once or self.proc.returncode != 0):
raise DHCPClientError(f'udhcpc{self._suffix} exited early with code {self.proc.returncode}')
if self.once:
self.await_ip()
else:
self.proc.terminate()
return self.ip
if self.proc.wait(timeout=timeout) != 0:
raise DHCPClientError(f'udhcpc{self._suffix} exited with non-zero exit code {self.proc.returncode}')
return self.ip
finally:
if self.netns:
self.proc.release()
self._shutdown_event.set()
self._event_thread.join()
self._event_queue.close()
self._event_queue.unlink()

Loading…
Cancel
Save