File tree Expand file tree Collapse file tree 3 files changed +12
-7
lines changed
Expand file tree Collapse file tree 3 files changed +12
-7
lines changed Original file line number Diff line number Diff line change 1+ Clean up some LoggingContext code.
Original file line number Diff line number Diff line change @@ -193,6 +193,12 @@ def connectionLost(self, reason):
193193 self .finish_time = time .time ()
194194 Request .connectionLost (self , reason )
195195
196+ if self .logcontext is None :
197+ logger .info (
198+ "Connection from %s lost before request headers were read" , self .client
199+ )
200+ return
201+
196202 # we only get here if the connection to the client drops before we send
197203 # the response.
198204 #
@@ -236,13 +242,6 @@ def _started_processing(self, servlet_name):
236242 def _finished_processing (self ):
237243 """Log the completion of this request and update the metrics
238244 """
239-
240- if self .logcontext is None :
241- # this can happen if the connection closed before we read the
242- # headers (so render was never called). In that case we'll already
243- # have logged a warning, so just bail out.
244- return
245-
246245 usage = self .logcontext .get_resource_usage ()
247246
248247 if self ._processing_finished_time is None :
Original file line number Diff line number Diff line change @@ -539,6 +539,11 @@ def set_current_context(context: LoggingContextOrSentinel) -> LoggingContextOrSe
539539 Returns:
540540 The context that was previously active
541541 """
542+ # everything blows up if we allow current_context to be set to None, so sanity-check
543+ # that now.
544+ if context is None :
545+ raise TypeError ("'context' argument may not be None" )
546+
542547 current = current_context ()
543548
544549 if current is not context :
You can’t perform that action at this time.
0 commit comments