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
This commit is contained in:
Gevorg Davoian 2016-05-06 15:36:18 +03:00
parent be16920f74
commit 776871f1a1
1 changed files with 7 additions and 1 deletions

View File

@ -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