Use _next_correlation_id() method to avoid int overflows
This commit is contained in:
@@ -143,9 +143,9 @@ class BrokerConnection(object):
|
|||||||
return future.failure(Errors.ConnectionError())
|
return future.failure(Errors.ConnectionError())
|
||||||
if not self.can_send_more():
|
if not self.can_send_more():
|
||||||
return future.failure(Errors.TooManyInFlightRequests())
|
return future.failure(Errors.TooManyInFlightRequests())
|
||||||
self._correlation_id += 1
|
correlation_id = self._next_correlation_id()
|
||||||
header = RequestHeader(request,
|
header = RequestHeader(request,
|
||||||
correlation_id=self._correlation_id,
|
correlation_id=correlation_id,
|
||||||
client_id=self._client_id)
|
client_id=self._client_id)
|
||||||
message = b''.join([header.encode(), request.encode()])
|
message = b''.join([header.encode(), request.encode()])
|
||||||
size = Int32.encode(len(message))
|
size = Int32.encode(len(message))
|
||||||
@@ -163,11 +163,11 @@ class BrokerConnection(object):
|
|||||||
log.exception("Error sending %s to %s", request, self)
|
log.exception("Error sending %s to %s", request, self)
|
||||||
self.close(error=e)
|
self.close(error=e)
|
||||||
return future.failure(e)
|
return future.failure(e)
|
||||||
log.debug('%s Request %d: %s', self, self._correlation_id, request)
|
log.debug('%s Request %d: %s', self, correlation_id, request)
|
||||||
|
|
||||||
if expect_response:
|
if expect_response:
|
||||||
ifr = InFlightRequest(request=request,
|
ifr = InFlightRequest(request=request,
|
||||||
correlation_id=self._correlation_id,
|
correlation_id=correlation_id,
|
||||||
response_type=request.RESPONSE_TYPE,
|
response_type=request.RESPONSE_TYPE,
|
||||||
future=future,
|
future=future,
|
||||||
timestamp=time.time())
|
timestamp=time.time())
|
||||||
@@ -299,6 +299,10 @@ class BrokerConnection(object):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def _next_correlation_id(self):
|
||||||
|
self._correlation_id = (self._correlation_id + 1) % 2**31
|
||||||
|
return self._correlation_id
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<BrokerConnection host=%s port=%d>" % (self.host, self.port)
|
return "<BrokerConnection host=%s port=%d>" % (self.host, self.port)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user