From e41880e8fa27e9089144f5fb0475b5a5950e5286 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Ma=C5=9Blanka?= <piotr.maslanka@henrietta.com.pl> Date: Fri, 3 Jan 2020 19:05:52 +0100 Subject: [PATCH] trying to solve that race condition --- LICENSE | 2 +- coolamqp/uplink/connection/connection.py | 8 ++++++-- coolamqp/uplink/handshake.py | 2 +- coolamqp/uplink/listener/epoll_listener.py | 4 +++- docs/conf.py | 2 +- setup.cfg | 2 +- 6 files changed, 13 insertions(+), 7 deletions(-) diff --git a/LICENSE b/LICENSE index 91e36a8..2de3c57 100644 --- a/LICENSE +++ b/LICENSE @@ -22,4 +22,4 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -resources/*: consult each file for respective copyright holders \ No newline at end of file +resources/*: consult each file for respective copyright holders diff --git a/coolamqp/uplink/connection/connection.py b/coolamqp/uplink/connection/connection.py index 78f5e07..0083a3c 100644 --- a/coolamqp/uplink/connection/connection.py +++ b/coolamqp/uplink/connection/connection.py @@ -176,11 +176,15 @@ class Connection(object): self.watch_for_method(0, (ConnectionClose, ConnectionCloseOk), self.on_connection_close) - self.sendf = SendingFramer(self.listener_socket.send) - Handshaker(self, self.node_definition, self.on_connected, self.extra_properties) + # Note that these are placed in just the right order. Sometimes there would + # be a race condition that ConnectionStart has arrived before there could + # be a watch for it set self.listener_socket = self.listener_thread.register(sock, on_read=self.recvf.put, on_fail=self.on_fail) + self.sendf = SendingFramer(self.listener_socket.send) + Handshaker(self, self.node_definition, self.on_connected, self.extra_properties) + self.listener_thread.activate(self.listener_socket) def on_fail(self): """ diff --git a/coolamqp/uplink/handshake.py b/coolamqp/uplink/handshake.py index 1b3526d..7724202 100644 --- a/coolamqp/uplink/handshake.py +++ b/coolamqp/uplink/handshake.py @@ -25,7 +25,7 @@ CLIENT_DATA = [ # because RabbitMQ is some kind of a fascist and does not allow # these fields to be of type short-string (b'product', (b'CoolAMQP', 'S')), - (b'version', (b'0.100a1', 'S')), + (b'version', (b'0.100', 'S')), (b'copyright', (b'Copyright (C) 2016-2020 SMOK sp. z o.o.', 'S')), ( b'information', ( diff --git a/coolamqp/uplink/listener/epoll_listener.py b/coolamqp/uplink/listener/epoll_listener.py index 1a42b71..796adc3 100644 --- a/coolamqp/uplink/listener/epoll_listener.py +++ b/coolamqp/uplink/listener/epoll_listener.py @@ -137,6 +137,9 @@ class EpollListener(object): callback )) + def activate(self, sock): # type: (coolamqp.uplink.listener.epoll_listener.EpollSocket) -> None + self.epoll.register(sock.sock, RW) + def register(self, sock, on_read=lambda data: None, on_fail=lambda: None): """ @@ -151,5 +154,4 @@ class EpollListener(object): sock = EpollSocket(sock, on_read, on_fail, self) self.fd_to_sock[sock.fileno()] = sock - self.epoll.register(sock, RW) return sock diff --git a/docs/conf.py b/docs/conf.py index 5333e6a..a087dcf 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -57,7 +57,7 @@ author = u'DMS Serwis s.c.' # The short X.Y version. version = '0.100' # The full version, including alpha/beta/rc tags. -release = u'0.100a1' +release = u'0.100' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/setup.cfg b/setup.cfg index 70fafaf..caac950 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,7 +1,7 @@ [metadata] description-file = README.md name = CoolAMQP -version = 0.100a1 +version = 0.100 license = MIT License classifiers = Programming Language :: Python -- GitLab