[PATCH] python/osmo-python-tests[master]: VTYInteract: monitor sockets opening and closing

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Fri Feb 24 16:53:41 UTC 2017


Review at  https://gerrit.osmocom.org/1904

VTYInteract: monitor sockets opening and closing

Not necessarily for merge, used to find a socket leak that caused 'Broken Pipe'
errors on our build slave.

Change-Id: I0cc7dc049c66f29fe58fee204e74aa9e82c21989
---
M osmopy/obscvty.py
1 file changed, 11 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/python/osmo-python-tests refs/changes/04/1904/1

diff --git a/osmopy/obscvty.py b/osmopy/obscvty.py
index 3c9edb1..6d615ab 100755
--- a/osmopy/obscvty.py
+++ b/osmopy/obscvty.py
@@ -32,6 +32,9 @@
     name is the name the vty prints for commands, ie OpenBSC
     host is the hostname to connect to
     port is the port to connect on"""
+
+    all_sockets = []
+
     def __init__(self, name, host, port):
         self.name = name
         self.host = host
@@ -44,6 +47,10 @@
 
     def _close_socket(self):
         if self.socket:
+            VTYInteract.all_sockets.remove(self.socket)
+            print "Socket: closing %s:%d %r (%d sockets open)" % (
+                    self.host, self.port, self.socket,
+                    len(VTYInteract.all_sockets))
             self.socket.close()
             self.socket = None
 
@@ -107,6 +114,10 @@
             self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
             self.socket.setblocking(1)
             self.socket.connect((self.host, self.port))
+            VTYInteract.all_sockets.append(self.socket)
+            print "Socket: connected to %s:%d %r (%d sockets open)" % (
+                    self.host, self.port, self.socket,
+                    len(VTYInteract.all_sockets))
             self.socket.recv(4096)
 
         # Now send the command

-- 
To view, visit https://gerrit.osmocom.org/1904
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0cc7dc049c66f29fe58fee204e74aa9e82c21989
Gerrit-PatchSet: 1
Gerrit-Project: python/osmo-python-tests
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>



More information about the gerrit-log mailing list