Example #1
0
    def _handle_frame(self, resp):
        recv_correlation_id, = struct.unpack_from(">i", resp, 0)

        correlation_id, resp_type, fut = self._requests.pop(0)
        if (self._api_version == (0, 8, 2)
                and resp_type is GroupCoordinatorResponse
                and correlation_id != 0 and recv_correlation_id == 0):
            self.log.warning('Kafka 0.8.2 quirk -- GroupCoordinatorResponse'
                             ' coorelation id does not match request. This'
                             ' should go away once at least one topic has been'
                             ' initialized on the broker')

        elif correlation_id != recv_correlation_id:
            error = Errors.CorrelationIdError(
                'Correlation ids do not match: sent {}, recv {}'.format(
                    correlation_id, recv_correlation_id))
            if not fut.done():
                fut.set_exception(error)
            self.close(reason=CloseReason.OUT_OF_SYNC)
            return

        if not fut.done():
            response = resp_type.decode(resp[4:])
            self.log.debug('%s Response %d: %s', self, correlation_id,
                           response)
            fut.set_result(response)
        # Update idle timer.
        self._last_action = self._loop.time()
Example #2
0
    def _read(self):
        try:
            while True:
                resp = yield from self._reader.readexactly(4)
                size, = self.HEADER.unpack(resp)

                resp = yield from self._reader.readexactly(size)

                recv_correlation_id, = self.HEADER.unpack(resp[:4])

                correlation_id, resp_type, fut = self._requests.pop(0)
                if (self._api_version == (0, 8, 2) and
                        resp_type is GroupCoordinatorResponse and
                        correlation_id != 0 and recv_correlation_id == 0):
                    self.log.warning(
                        'Kafka 0.8.2 quirk -- GroupCoordinatorResponse'
                        ' coorelation id does not match request. This'
                        ' should go away once at least one topic has been'
                        ' initialized on the broker')

                elif correlation_id != recv_correlation_id:
                    error = Errors.CorrelationIdError(
                        'Correlation ids do not match: sent {}, recv {}'
                        .format(correlation_id, recv_correlation_id))
                    if not fut.done():
                        fut.set_exception(error)
                    self.close(reason=CloseReason.OUT_OF_SYNC)
                    break

                if not fut.done():
                    response = resp_type.decode(resp[4:])
                    self.log.debug('%s Response %d: %s',
                                   self, correlation_id, response)
                    fut.set_result(response)
                # Update idle timer.
                self._last_action = self._loop.time()
        except (OSError, EOFError, ConnectionError) as exc:
            for _, _, fut in self._requests:
                conn_exc = Errors.ConnectionError(
                    "Connection at {0}:{1} broken"
                    .format(self._host, self._port))
                conn_exc.__cause__ = exc
                conn_exc.__context__ = exc
                fut.set_exception(conn_exc)
            self.close(reason=CloseReason.CONNECTION_BROKEN)
        except asyncio.CancelledError:
            pass
Example #3
0
    def _handle_frame(self, resp):
        correlation_id, resp_type, fut = self._requests[0]

        if correlation_id is None:  # Is a SASL packet, just pass it though
            if not fut.done():
                fut.set_result(resp)
        else:

            recv_correlation_id, = struct.unpack_from(">i", resp, 0)

            if (self._api_version == (0, 8, 2)
                    and resp_type is GroupCoordinatorResponse
                    and correlation_id != 0 and recv_correlation_id == 0):
                self.log.warning(
                    'Kafka 0.8.2 quirk -- GroupCoordinatorResponse'
                    ' coorelation id does not match request. This'
                    ' should go away once at least one topic has been'
                    ' initialized on the broker')

            elif correlation_id != recv_correlation_id:
                error = Errors.CorrelationIdError(
                    'Correlation ids do not match: sent {}, recv {}'.format(
                        correlation_id, recv_correlation_id))
                if not fut.done():
                    fut.set_exception(error)
                self.close(reason=CloseReason.OUT_OF_SYNC)
                return

            if not fut.done():
                response = resp_type.decode(resp[4:])
                self.log.debug('%s Response %d: %s', self, correlation_id,
                               response)
                fut.set_result(response)

        # Update idle timer.
        self._last_action = time.monotonic()
        # We should clear the request future only after all code is done and
        # future is resolved. If any fails it's up to close() method to fail
        # this future.
        self._requests.popleft()