From 776871f1a12690d80abb78007318330630ef0cdf Mon Sep 17 00:00:00 2001 From: Gevorg Davoian Date: Fri, 6 May 2016 15:36:18 +0300 Subject: [PATCH] Rabbit driver: failure of rpc-calls with float timeout This patch fixes the bug discovered in the rabbbit driver and related to invoking rpc-calls with floating-point timeouts. Change-Id: Ic4742e08ecaa892382c6a2d4810f6cf7296ee8e8 Closes-Bug: 1579029 --- oslo_messaging/_drivers/impl_rabbit.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/oslo_messaging/_drivers/impl_rabbit.py b/oslo_messaging/_drivers/impl_rabbit.py index 259e8d616..4c874ee08 100644 --- a/oslo_messaging/_drivers/impl_rabbit.py +++ b/oslo_messaging/_drivers/impl_rabbit.py @@ -17,6 +17,7 @@ import contextlib import errno import functools import itertools +import math import os import random import socket @@ -873,9 +874,14 @@ class Connection(object): if sys.platform != 'win32' and sys.platform != 'darwin': try: timeout = timeout * 1000 if timeout is not None else 0 + # NOTE(gdavoian): only integers and strings are allowed + # as socket options' values, and TCP_USER_TIMEOUT option + # can take only integer values, so we round-up the timeout + # to the nearest integer in order to ensure that the + # connection is not broken before the expected timeout sock.setsockopt(socket.IPPROTO_TCP, TCP_USER_TIMEOUT, - timeout) + int(math.ceil(timeout))) except socket.error as error: code = error[0] # TCP_USER_TIMEOUT not defined on kernels <2.6.37