Skip to content

Commit 6db14de

Browse files
committed
Merge pull request #107 from rdiomar/fix_default_timeouts
Increase default connection timeout
2 parents 21e9438 + ef24c11 commit 6db14de

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

kafka/client.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
BrokerResponseError, PartitionUnavailableError,
1111
KafkaUnavailableError, KafkaRequestError)
1212

13-
from kafka.conn import KafkaConnection
13+
from kafka.conn import KafkaConnection, DEFAULT_SOCKET_TIMEOUT_SECONDS
1414
from kafka.protocol import KafkaProtocol
1515

1616
log = logging.getLogger("kafka")
@@ -21,7 +21,11 @@ class KafkaClient(object):
2121
CLIENT_ID = "kafka-python"
2222
ID_GEN = count()
2323

24-
def __init__(self, host, port, client_id=CLIENT_ID, timeout=10):
24+
# NOTE: The timeout given to the client should always be greater than the
25+
# one passed to SimpleConsumer.get_message(), otherwise you can get a
26+
# socket timeout.
27+
def __init__(self, host, port, client_id=CLIENT_ID,
28+
timeout=DEFAULT_SOCKET_TIMEOUT_SECONDS):
2529
# We need one connection to bootstrap
2630
self.client_id = client_id
2731
self.timeout = timeout

kafka/conn.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
log = logging.getLogger("kafka")
1010

11+
DEFAULT_SOCKET_TIMEOUT_SECONDS = 120
1112

1213
class KafkaConnection(local):
1314
"""
@@ -17,8 +18,13 @@ class KafkaConnection(local):
1718
by a call to `recv` in order to get the correct response. Eventually,
1819
we can do something in here to facilitate multiplexed requests/responses
1920
since the Kafka API includes a correlation id.
21+
22+
host: the host name or IP address of a kafka broker
23+
port: the port number the kafka broker is listening on
24+
timeout: default 120. The socket timeout for sending and receiving data
25+
in seconds. None means no timeout, so a request can block forever.
2026
"""
21-
def __init__(self, host, port, timeout=10):
27+
def __init__(self, host, port, timeout=DEFAULT_SOCKET_TIMEOUT_SECONDS):
2228
super(KafkaConnection, self).__init__()
2329
self.host = host
2430
self.port = port

0 commit comments

Comments
 (0)