Avoid crash due to POLLIN event check

Fixed bug which prevented use on newer version of python as we
incorrectly checked event value against the bitmask.

Also improves exception by included value of the event in it.

Change-Id: I49f41d2555f53f2377c32c7626e1350c4f42b8de
This commit is contained in:
Sorin Sbarnea 2020-05-21 15:02:21 +01:00 committed by zbr
parent 73005984a9
commit 12e395e8ea
1 changed files with 7 additions and 2 deletions

View File

@ -15,6 +15,7 @@
import json
import logging
import platform
import pprint
import select
import six.moves
@ -34,6 +35,7 @@ UPDATE_ALLOWED_KEYS = ['description', 'submit-type',
'content-merge', 'change-id',
'project-state',
'max-object-size-limit']
IS_LINUX = platform.system() == "Linux"
class GerritConnection(object):
@ -148,10 +150,13 @@ class GerritWatcher(threading.Thread):
ret = poll.poll()
for (fd, event) in ret:
if fd == stdout.channel.fileno():
if event == select.POLLIN:
# event is a bitmask
# On Darwin non-critical OOB messages can be received
if (IS_LINUX and event == select.POLLIN) or \
(not IS_LINUX and event & select.POLLIN):
self._read(stdout)
else:
raise Exception("event on ssh connection")
raise Exception("event %s on ssh connection" % event)
def _consume(self, client):
"""Consumes events using the given client."""