def on_error(self, exception): """Common functions when a socket error occurs. Make sure to set closed and add the exception, and note an exception event. :param socket.error exception: The socket error """ args = [self._args['host'], self._args['port'], str(exception)] if self._channels[0][0].open: self._exceptions.put(exceptions.ConnectionResetException(*args)) else: self._exceptions.put(exceptions.ConnectionException(*args)) self._events.set(events.EXCEPTION_RAISED)
def run(self): self._data.running = True while self._data.running: try: self._poll() except EnvironmentError as exception: if (getattr(exception, 'errno', None) == errno.EINTR or (isinstance(getattr(exception, 'args', None), tuple) and len(exception.args) == 2 and exception.args[0] == errno.EINTR)): continue if self._data.events.is_set(events.SOCKET_CLOSE): LOGGER.debug('Exiting due to closed socket') self._exceptions.put(exceptions.ConnectionResetException()) break LOGGER.debug('Exiting IOLoop.run')
def _on_connection_start(self, frame_value): """Negotiate the Connection.Start process, writing out a Connection.StartOk frame when the Connection.Start frame is received. :type frame_value: pamqp.specification.Connection.Start :raises: rabbitpy.exceptions.ConnectionException """ if not self._validate_connection_start(frame_value): LOGGER.error('Could not negotiate a connection, disconnecting') raise exceptions.ConnectionResetException() self.properties = frame_value.server_properties for key in self.properties: if key == 'capabilities': for capability in self.properties[key]: LOGGER.debug('Server supports %s: %r', capability, self.properties[key][capability]) else: LOGGER.debug('Server %s: %r', key, self.properties[key]) self.write_frame(self._build_start_ok_frame())
def _check(self): # If the byte count has incremented no need to check time if self._io.bytes_received > self._last_bytes: LOGGER.debug('Data has been received, exiting heartbeat check') self._lock.acquire(True) self._last_bytes = self._io.bytes_received self._lock.release() self._start_timer() return age = time.time() - self._last_heartbeat threshold = self._interval * self.MAX_MISSED_HEARTBEATS LOGGER.debug('Checking for heartbeat, last: %i sec ago, threshold: %i', age, threshold) if age >= threshold: LOGGER.error('Have not received a heartbeat in %i seconds', age) message = 'No heartbeat in {0} seconds'.format(age) self._exceptions.put(exceptions.ConnectionResetException(message)) else: self._start_timer()
def run(self): """Run the IOLoop, blocking until the socket is closed or there is another exception. """ self._data.running = True while self._data.running: try: self._poll() except EnvironmentError as exception: if getattr(exception, 'errno') == errno.EINTR: continue elif (isinstance(getattr(exception, 'args'), tuple) and len(exception.args) == 2 and exception.args[0] == errno.EINTR): continue if self._data.events.is_set(events.SOCKET_CLOSE): LOGGER.debug('Exiting due to closed socket') self._exceptions.put(exceptions.ConnectionResetException()) break LOGGER.debug('Exiting IOLoop.run')
def _check_for_heartbeat(self): """Check to ensure that a heartbeat has occurred in the last heartbeat interval * 2 seconds. Raises an ``exceptions.ConnectionResetException`` if not. :raises: exceptions.ConnectionResetException """ if not self._last_heartbeat: LOGGER.debug('No heartbeat received') return age = time.time() - self._last_heartbeat threshold = self._heartbeat * self.MAX_MISSED_HEARTBEATS LOGGER.debug('Checking for heartbeat, last: %i sec ago, threshold: %i', age, threshold) if age > threshold: LOGGER.error('Have not received a heartbeat in %i seconds', age) message = 'No heartbeat in {0} seconds'.format(age) self._exceptions.put(exceptions.ConnectionResetException(message)) self._trigger_write() else: self._start_heartbeat_timer()