Skip to content

Commit

Permalink
facade: fix file descriptor leak during comms errors
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbonney committed Jan 4, 2019
1 parent 02da023 commit d0b3900
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# NMOS Common Library Changelog

## 0.9.2
- Fix file descriptor leak in facade class

## 0.9.1
- Handle uncaught mDNS exceptions and manage double calls to start mDNSEngine

Expand Down
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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def find_packages(path, base=""):


setup(name="nmoscommon",
version="0.9.1",
version="0.9.2",
description="Common components for the BBC's NMOS implementations",
url='https://github.com/bbc/nmos-common',
author='Peter Brightwell',
Expand Down

0 comments on commit d0b3900

Please sign in to comment.