Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Fix "'NoneType' has no attribute start|stop" logcontext errors
Browse files Browse the repository at this point in the history
Fixes #7179.
  • Loading branch information
richvdh committed Mar 31, 2020
1 parent 7966a1c commit 564de6c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions changelog.d/7181.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Clean up some LoggingContext code.
13 changes: 6 additions & 7 deletions synapse/http/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@ def connectionLost(self, reason):
self.finish_time = time.time()
Request.connectionLost(self, reason)

if self.logcontext is None:
logger.info(
"Connection from %s lost before request headears were read", self.client
)
return

# we only get here if the connection to the client drops before we send
# the response.
#
Expand Down Expand Up @@ -236,13 +242,6 @@ def _started_processing(self, servlet_name):
def _finished_processing(self):
"""Log the completion of this request and update the metrics
"""

if self.logcontext is None:
# this can happen if the connection closed before we read the
# headers (so render was never called). In that case we'll already
# have logged a warning, so just bail out.
return

usage = self.logcontext.get_resource_usage()

if self._processing_finished_time is None:
Expand Down
5 changes: 5 additions & 0 deletions synapse/logging/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,11 @@ def set_current_context(context: LoggingContextOrSentinel) -> LoggingContextOrSe
Returns:
The context that was previously active
"""
# everything blows up if we allow current_context to be set to None, so sanity-check
# that now.
if context is None:
raise TypeError("'context' argument may not be None")

current = current_context()

if current is not context:
Expand Down

0 comments on commit 564de6c

Please sign in to comment.