Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Jormungandr Python3.9]Set handshake_ivl to 0 #3961

Merged
merged 5 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions source/jormungandr/jormungandr/transient_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
from datetime import datetime, timedelta
from navitiacommon import response_pb2

zmq_version = [int(n) for n in zmq.zmq_version().split(".")[:2]]

# ZMQ_HANDSHAKE_IVL is available from 4.2.x
SET_ZMQ_HANDSHAKE_IVL = zmq_version[0] > 4 or (zmq_version[0] == 4 and zmq_version[1] >= 2)


class TransientSocket(object):
"""
Expand Down Expand Up @@ -76,6 +81,27 @@ def __init__(self, name, zmq_context, zmq_socket, socket_ttl, *args, **kwargs):
def make_new_socket(self):
start = time.time()
socket = self._zmq_context.socket(zmq.REQ)
# During the migration to debian 11, the socket was closed by server because of HANDSHAKE_FAILED_NO_DETAIL
# exception.
# This is very likely due to the fact that jormungandr(client) and kraken(server) are not using the same version
# of libzmq.
# In the recent version (4.3.x), client need to HANDSHAKE with the server the exchange the configuration
# information of the socket.
# Search for ZMQ_HANDSHAKE_IVL on this page: http://api.zeromq.org/4-3:zmq-setsockopt

# When it comes to debian8, on which runs kraken, this option is not existent:
# https://manpages.debian.org/jessie/libzmq-dev/zmq_setsockopt.3.en.html

# As to Asgard, no HANDSHAKE_FAILED_NO_DETAIL exception has been encountered since Asgard runs on ubuntu20,
# which has a recent version of libzmq

# The workaround:
# since jormungandr renew the zmq socket at the interval of ZMQ_SOCKET_TTL_SECONDS,
# we just need to make sure that the socket is renewed before HANDSHAKE_FAILED_NO_DETAIL is raised, hence
# setsockopt(zmq.HANDSHAKE_IVL, 0)
if SET_ZMQ_HANDSHAKE_IVL:
socket.setsockopt(zmq.HANDSHAKE_IVL, 0)

socket.connect(self._zmq_socket)
self._logger.debug(
"it took %s ms to open a socket of %s",
Expand Down
2 changes: 1 addition & 1 deletion source/jormungandr/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ protobuf==3.15.0
psycopg2 ; python_version < "3.9"
psycopg2-binary ; python_version >= "3.9"
pyzmq==15.4.0 ; python_version < "3.9"
pyzmq==22.3.0 ; python_version >= "3.9"
pyzmq==25.0.2 ; python_version >= "3.9"
six==1.13.0
python-dateutil==2.5.3
pytz==2013.9
Expand Down