Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

facade: fix file descriptor leak during comms errors #66

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions nmoscommon/facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ def setup_ipc(self):
except Exception:
self.ipc = None

def close_ipc(self):
with self.lock:
if self.ipc:
self.ipc.close()
self.ipc = None

def register_service(self, href, proxy_path):
self.logger.writeInfo("Register service")
self.href = href
Expand All @@ -72,7 +78,7 @@ def register_service(self, href, proxy_path):
self.logger.writeInfo("Service registration failed: {}".format(self.debug_message(s)))
except Exception as e:
self.logger.writeError("Exception when registering service: {}".format(str(e)))
self.ipc = None
self.close_ipc()

def unregister_service(self):
if not self.ipc:
Expand All @@ -85,7 +91,7 @@ def unregister_service(self):
self.srv_registered = False
except Exception as e:
self.logger.writeError("Exception when unregistering service: {}".format(str(e)))
self.ipc = None
self.close_ipc()

def heartbeat_service(self):
if not self.ipc:
Expand All @@ -106,7 +112,7 @@ def heartbeat_service(self):
self.reregister_all()
except Exception as e:
self.logger.writeError("Exception when heartbeating service: {}".format(str(e)))
self.ipc = None
self.close_ipc()

# ONLY call this directly from within heartbeat_service!
# To cause a re-registration on failure, set self.reregister!
Expand Down