def connectionLost(self, reason: Union[Failure, Exception]) -> None: """Called when the client connection is closed before the response is written. Overrides twisted.web.server.Request.connectionLost to record the finish time and do logging. """ # There is a bug in Twisted where reason is not wrapped in a Failure object # Detect this and wrap it manually as a workaround # More information: https://github.com/matrix-org/synapse/issues/7441 if not isinstance(reason, Failure): reason = Failure(reason) self.finish_time = time.time() Request.connectionLost(self, reason) if self.logcontext is None: logger.info( "Connection from %s lost before request headers were read", self.client) return # we only get here if the connection to the client drops before we send # the response. # # It's useful to log it here so that we can get an idea of when # the client disconnects. with PreserveLoggingContext(self.logcontext): logger.info("Connection from client lost before response was sent") if not self._is_processing: self._finished_processing()
def connectionLost(self, reason: Union[Failure, Exception]) -> None: """Called when the client connection is closed before the response is written. Overrides twisted.web.server.Request.connectionLost to record the finish time and do logging. """ # There is a bug in Twisted where reason is not wrapped in a Failure object # Detect this and wrap it manually as a workaround # More information: https://github.com/matrix-org/synapse/issues/7441 if not isinstance(reason, Failure): reason = Failure(reason) self.finish_time = time.time() Request.connectionLost(self, reason) if self.logcontext is None: logger.info( "Connection from %s lost before request headers were read", self.client) return # we only get here if the connection to the client drops before we send # the response. # # It's useful to log it here so that we can get an idea of when # the client disconnects. with PreserveLoggingContext(self.logcontext): logger.info("Connection from client lost before response was sent") if self._opentracing_span: self._opentracing_span.log_kv({ "event": "client connection lost", "reason": str(reason.value) }) if self._is_processing: if self.is_render_cancellable: if self.render_deferred is not None: # Throw a cancellation into the request processing, in the hope # that it will finish up sooner than it normally would. # The `self.processing()` context manager will call # `_finished_processing()` when done. with PreserveLoggingContext(): self.render_deferred.cancel() else: logger.error( "Connection from client lost, but have no Deferred to " "cancel even though the request is marked as cancellable." ) else: self._finished_processing()
def connectionLost(self, reason): """Called when the client connection is closed before the response is written. Overrides twisted.web.server.Request.connectionLost to record the finish time and do logging. """ self.finish_time = time.time() Request.connectionLost(self, reason) # we only get here if the connection to the client drops before we send # the response. # # It's useful to log it here so that we can get an idea of when # the client disconnects. with PreserveLoggingContext(self.logcontext): logger.warning("Error processing request %r: %s %s", self, reason.type, reason.value) if not self._is_processing: self._finished_processing()
def connectionLost(self, reason): """Called when the client connection is closed before the response is written. Overrides twisted.web.server.Request.connectionLost to record the finish time and do logging. """ self.finish_time = time.time() Request.connectionLost(self, reason) # we only get here if the connection to the client drops before we send # the response. # # It's useful to log it here so that we can get an idea of when # the client disconnects. with PreserveLoggingContext(self.logcontext): logger.warn( "Error processing request %r: %s %s", self, reason.type, reason.value, ) if not self._is_processing: self._finished_processing()