From 12e395e8eabd312c2eb0f991282ea7c86c7a9b29 Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Thu, 21 May 2020 15:02:21 +0100 Subject: [PATCH] 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 --- gerritlib/gerrit.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/gerritlib/gerrit.py b/gerritlib/gerrit.py index 0089bc9..3d78fca 100644 --- a/gerritlib/gerrit.py +++ b/gerritlib/gerrit.py @@ -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."""