Skip to content

Commit

Permalink
ost_utils: async abort of hanging connection
Browse files Browse the repository at this point in the history
Use python's signal to abort a vmconsole connection that is hanging
forever.

Change-Id: I631f206b3f2fbf61dd0cd1f5337c4e58830fc18a
Signed-off-by: Eitan Raviv <eraviv@redhat.com>
  • Loading branch information
erav authored and mrkev-gh committed Sep 22, 2022
1 parent ba413e5 commit 068a3c4
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ost_utils/vmconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ def connect(self, vm_id):
@contextlib.contextmanager
def _connect(self, vm_id):
try:
alarm = BlockingIOAlarm('timed out waiting to connect', 180)
signal.signal(signal.SIGALRM, alarm.handle)
signal.alarm(alarm.seconds)
master, slave = pty.openpty()
LOGGER.debug('vmconsole: opened pty')
args = [
Expand All @@ -80,13 +83,15 @@ def _connect(self, vm_id):
stdout=subprocess.PIPE,
bufsize=0,
)
signal.alarm(0) # cancel
LOGGER.debug(f'vmconsole: opened reader with args {args}')
self._writer = os.fdopen(master, 'w')
LOGGER.debug('vmconsole: opened writer')
self._connected = True
yield
finally:
self._disconnect()
signal.signal(signal.SIGALRM, signal.SIG_DFL)

def _disconnect(self):
LOGGER.debug('vmconsole: disconnecting...')
Expand Down

0 comments on commit 068a3c4

Please sign in to comment.