#12632 closed defect (fixed)
TracError while post-processing leads noisy logging
Reported by: | Jun Omae | Owned by: | Jun Omae |
---|---|---|---|
Priority: | normal | Milestone: | 1.0.14 |
Component: | general | Version: | |
Severity: | normal | Keywords: | |
Cc: | Branch: | ||
Release Notes: |
|
||
API Changes: | |||
Internal Changes: |
Description (last modified by )
TracError
while executing process_request()
is logged with WARNING level and no traceback. However, same exception while post-processing is logged with ERROR level and traceback. That's noisy….
See gmessage:trac-users:4tVRBotYrZs/NB3ZjUYjCAAJ.
-
trac/web/main.py
diff --git a/trac/web/main.py b/trac/web/main.py index 34a43039c..6406f54b3 100644
a b class RequestDispatcher(Component): 280 280 except RequestDone: 281 281 raise 282 282 except Exception, e: 283 self.log.error("Exception caught while post-processing" 284 " request: %s", 285 exception_to_unicode(e, traceback=True)) 283 self.log.error( 284 "Exception caught while post-processing request: %s", 285 exception_to_unicode( 286 e, traceback=not isinstance(TracError, e))) 286 287 raise err[0], err[1], err[2] 287 288 except PermissionError, e: 288 289 raise HTTPForbidden(e)
Attachments (0)
Change History (20)
comment:2 by , 8 years ago
Description: | modified (diff) |
---|
comment:3 by , 8 years ago
Yeah, I agree we don't need traceback in case of TracError
. I think it could be moved to milestone:next-stable-1.2.x.
comment:4 by , 8 years ago
Milestone: | next-stable-1.0.x → 1.2.1 |
---|---|
Owner: | set to |
Status: | new → assigned |
Okay. I'll push 2nd patch to 1.2-stable branch.
comment:5 by , 8 years ago
I have no problem if you'd like to push to 1.0-stable, I was just thinking that in general we won't be doing as many fixes on that branch since 1.2 is released. I won't get around to releasing 1.0.14 for at least another 24 hours or so, so the change could be included in that release if you felt it was needed.
comment:6 by , 8 years ago
Milestone: | 1.2.1 → 1.0.14 |
---|---|
Release Notes: | modified (diff) |
Resolution: | → fixed |
Status: | assigned → closed |
Thanks. I reconsider it should be pushed to 1.0-stable. Committed to 1.0-stable in [15290] and merged in [15291-15292].
After [15290], TracError
while post-processing is logged like this:
2016-12-07 17:35:17,894 Trac[main] WARNING: Exception caught while post-processing request: TracError: #12632 2016-12-07 17:35:17,894 Trac[main] WARNING: [192.168.11.21] HTTPInternalError: 500 Trac Error (#12632)
Other exceptions while post-processing is logged like this:
2016-12-07 17:38:17,646 Trac[main] ERROR: Exception caught while post-processing request: Traceback (most recent call last): File "/src/tracdev/svn/branches/1.0-stable/trac/web/main.py", line 279, in dispatch self._post_process_request(req) File "/src/tracdev/svn/branches/1.0-stable/trac/web/main.py", line 403, in _post_process_request f.post_process_request(req, *(None,)*extra_arg_count) File "/var/trac/1.0-sqlite/plugins/t12632.py", line 12, in post_process_request raise TypeError('#12632') TypeError: #12632 2016-12-07 17:38:17,646 Trac[main] ERROR: Internal Server Error: <RequestWithSession "GET '/about'">, referrer None Traceback (most recent call last): File "/src/tracdev/svn/branches/1.0-stable/trac/web/main.py", line 567, in _dispatch_request dispatcher.dispatch(req) File "/src/tracdev/svn/branches/1.0-stable/trac/web/main.py", line 259, in dispatch self._post_process_request(req, *resp) File "/src/tracdev/svn/branches/1.0-stable/trac/web/main.py", line 401, in _post_process_request resp = f.post_process_request(req, *resp) File "/var/trac/1.0-sqlite/plugins/t12632.py", line 12, in post_process_request raise TypeError('#12632') TypeError: #12632
comment:7 by , 8 years ago
Looking at a traceback such as th:comment:17:ticket:11869 and considering how to reproduce the error, what do you think about adding req.path_info
to the log message?
comment:8 by , 8 years ago
Sounds good. Also, we could add req.remote_addr
to logging when internal error is occurred.
-
trac/web/main.py
diff --git a/trac/web/main.py b/trac/web/main.py index ce2e81437..42aea7bda 100644
a b def _dispatch_request(req, env, env_error): 578 578 def _send_user_error(req, env, e): 579 579 # See trac/web/api.py for the definition of HTTPException subclasses. 580 580 if env: 581 env.log.warn('[%s] %s', req.remote_addr, exception_to_unicode(e)) 581 env.log.warning('[%s] %s, %r, referrer %r', 582 req.remote_addr, exception_to_unicode(e), req, 583 req.environ.get('HTTP_REFERER')) 582 584 data = {'title': e.title, 'type': 'TracError', 'message': e.message, 583 585 'frames': [], 'traceback': None} 584 586 if e.code == 403 and req.authname == 'anonymous': … … def _send_user_error(req, env, e): 594 596 595 597 def send_internal_error(env, req, exc_info): 596 598 if env: 597 env.log.error(" Internal Server Error: %r, referrer %r%s",598 req , req.environ.get('HTTP_REFERER'),599 env.log.error("[%s] Internal Server Error: %r, referrer %r%s", 600 req.remote_addr, req, req.environ.get('HTTP_REFERER'), 599 601 exception_to_unicode(exc_info[1], traceback=True)) 600 602 message = exception_to_unicode(exc_info[1]) 601 603 traceback = get_last_traceback()
2016-12-09 18:52:18,854 Trac[main] WARNING: Exception caught while post-processing request: TracError: #12632 2016-12-09 18:52:18,854 Trac[main] WARNING: [192.168.11.21] HTTPInternalError: 500 Trac Error (#12632), <RequestWithSession "GET '/admin'">, referrer None
2016-12-09 18:52:46,975 Trac[main] ERROR: Exception caught while post-processing request: Traceback (most recent call last): File "/src/tracdev/git/trac/web/main.py", line 279, in dispatch self._post_process_request(req) File "/src/tracdev/git/trac/web/main.py", line 403, in _post_process_request f.post_process_request(req, *(None,)*extra_arg_count) File "/var/trac/1.0-sqlite/plugins/t12632.py", line 12, in post_process_request raise TypeError('#12632') TypeError: #12632 2016-12-09 18:52:46,976 Trac[main] ERROR: [192.168.11.21] Internal Server Error: <RequestWithSession "GET '/admin'">, referrer None Traceback (most recent call last): File "/src/tracdev/git/trac/web/main.py", line 567, in _dispatch_request dispatcher.dispatch(req) File "/src/tracdev/git/trac/web/main.py", line 259, in dispatch self._post_process_request(req, *resp) File "/src/tracdev/git/trac/web/main.py", line 401, in _post_process_request resp = f.post_process_request(req, *resp) File "/var/trac/1.0-sqlite/plugins/t12632.py", line 12, in post_process_request raise TypeError('#12632') TypeError: #12632
comment:9 by , 8 years ago
comment:10 by , 8 years ago
Recently I've been seeing this traceback in the logs:
[pid 9560 140352200652544] 2017-02-12 05:50:01,137 Trac[main] ERROR: Exception caught while post-processing request: Traceback (most recent call last): File "build/bdist.linux-x86_64/egg/trac/web/main.py", line 286, in dispatch self._post_process_request(req) File "build/bdist.linux-x86_64/egg/trac/web/main.py", line 463, in _post_process_request f.post_process_request(req, *(None,) * extra_arg_count) File "build/bdist.linux-x86_64/egg/trac/ticket/batch.py", line 83, in post_process_request if req.path_info == '/query' and \ File "build/bdist.linux-x86_64/egg/trac/web/api.py", line 581, in path_info path_info=path_info))
It looks like incorrect encoding of path_info
is raising an exception in post_processing_request
of BatchModule
and the exception is trapped and logged. Maybe we should just re-raise some or all exceptions that inherit from HTTPException
, or at least for HTTPNotFound
?
follow-up: 13 comment:11 by , 8 years ago
Traceback can be reproduced with a path containing an invalid byte sequence, such as /milestone/%AD
:
14:34:02 Trac[main] ERROR: Exception caught while post-processing request: Traceback (most recent call last): File "/Users/rjollos/Documents/Workspace/trac-dev/teo-rjollos.git/trac/web/main.py", line 285, in dispatch self._post_process_request(req) File "/Users/rjollos/Documents/Workspace/trac-dev/teo-rjollos.git/trac/web/main.py", line 454, in _post_process_request f.post_process_request(req, *(None,)*extra_arg_count) File "/Users/rjollos/Documents/Workspace/trac-dev/teo-rjollos.git/trac/ticket/batch.py", line 84, in post_process_request if req.path_info == '/query' and \ File "/Users/rjollos/Documents/Workspace/trac-dev/teo-rjollos.git/trac/web/api.py", line 526, in path_info path_info=path_info)) HTTPNotFound: 404 Not Found (Invalid URL encoding (was '/milestone/\xad')) 14:34:02 Trac[main] WARNING: [127.0.0.1] HTTPNotFound: 404 Not Found (Invalid URL encoding (was '/milestone/\xad')), <RequestWithSession "GET '/milestone/\xad'">, referrer None
With this patch:
-
trac/web/main.py
diff --git a/trac/web/main.py b/trac/web/main.py index b0680ab5b..20dcd35c9 100644
a b class RequestDispatcher(Component): 289 289 if isinstance(e, TracError): 290 290 self.log.warning("Exception caught while post-processing" 291 291 " request: %s", exception_to_unicode(e2)) 292 el se:292 elif not HTTPException: 293 293 self.log.error("Exception caught while post-processing" 294 294 " request: %s", 295 295 exception_to_unicode(e2, traceback=True))
log message would be:
14:34:39 Trac[main] WARNING: [127.0.0.1] HTTPNotFound: 404 Not Found (Invalid URL encoding (was '/milestone/\xad')), <RequestWithSession "GET '/milestone/\xad'">, referrer None
follow-up: 14 comment:12 by , 8 years ago
The following line is weird.
except Exception as e2: - if isinstance(e, TracError): + if isinstance(e2, TracError): self.log.warning("Exception caught while post-processing" " request: %s", exception_to_unicode(e2))
follow-up: 15 comment:13 by , 8 years ago
Replying to Ryan J Ollos:
Traceback can be reproduced with a path containing an invalid byte sequence, such as
/milestone/%AD
:[…]
With this patch:
trac/web/main.py
diff --git a/trac/web/main.py b/trac/web/main.py index b0680ab5b..20dcd35c9 100644
a b class RequestDispatcher(Component): 289 289 if isinstance(e, TracError): 290 290 self.log.warning("Exception caught while post-processing" 291 291 " request: %s", exception_to_unicode(e2)) 292 el se:292 elif not HTTPException: 293 293 self.log.error("Exception caught while post-processing" 294 294 " request: %s", 295 295 exception_to_unicode(e2, traceback=True))
I don't think we should just ignore the exception while post-processing. However, if you'd like to ignore it, it would be simple like this:
-
trac/web/main.py
diff --git a/trac/web/main.py b/trac/web/main.py index b0680ab5b..868b2b62c 100644
a b class RequestDispatcher(Component): 283 283 err = sys.exc_info() 284 284 try: 285 285 self._post_process_request(req) 286 except RequestDone:286 except (RequestDone, HTTPException): 287 287 pass 288 288 except Exception as e2: 289 289 if isinstance(e, TracError):
This noisy logging is lead when the same exception is raised from pre_process_request
/process_request
and post_process_request
. In the case, we could log the exception without traceback or ignore.
-
trac/web/main.py
diff --git a/trac/web/main.py b/trac/web/main.py index b0680ab5b..83894e596 100644
a b class RequestDispatcher(Component): 286 286 except RequestDone: 287 287 pass 288 288 except Exception as e2: 289 if isinstance(e, TracError): 289 if isinstance(e2, TracError) or \ 290 type(e) is type(e2) and e.args == e2.args: 290 291 self.log.warning("Exception caught while post-processing" 291 292 " request: %s", exception_to_unicode(e2)) 292 293 else:
follow-up: 17 comment:14 by , 8 years ago
follow-up: 16 comment:15 by , 8 years ago
Replying to Jun Omae:
I don't think we should just ignore the exception while post-processing.
I'm not suggesting we ignore it, I'm suggesting it doesn't need to get logged with traceback because we can allow the exception to propagate and it will be logged as shown in comment:11.
comment:16 by , 8 years ago
Replying to Ryan J Ollos:
Replying to Jun Omae:
I don't think we should just ignore the exception while post-processing.
I'm not suggesting we ignore it, I'm suggesting it doesn't need to get logged with traceback because we can allow the exception to propagate and it will be logged as shown in comment:11.
I think we should check whether e
and e2
are same if we'd like to do it.
Also, I think that elif not HTTPException
is programming error. The following line in comment:11 should be:
- elif not HTTPException: + elif not isinstance(e2, HTTPException):
comment:17 by , 8 years ago
Replying to Ryan J Ollos:
Replying to Jun Omae:
The following line is weird.
except Exception as e2: - if isinstance(e, TracError): + if isinstance(e2, TracError): self.log.warning("Exception caught while post-processing" " request: %s", exception_to_unicode(e2))That appears to be due to the merge in r15291.
Ahh, my bad. isinstance(e, exception-type)
in except
statements is bad pattern.
-
trac/web/main.py
diff --git a/trac/web/main.py b/trac/web/main.py index b0680ab5b..52a9c7ebf 100644
a b class RequestDispatcher(Component): 285 285 self._post_process_request(req) 286 286 except RequestDone: 287 287 pass 288 except TracError as e2: 289 self.log.warning("Exception caught while post-processing" 290 " request: %s", exception_to_unicode(e2)) 288 291 except Exception as e2: 289 if isinstance(e, TracError): 290 self.log.warning("Exception caught while post-processing" 291 " request: %s", exception_to_unicode(e2)) 292 else: 293 self.log.error("Exception caught while post-processing" 294 " request: %s", 295 exception_to_unicode(e2, traceback=True)) 292 self.log.error("Exception caught while post-processing" 293 " request: %s", 294 exception_to_unicode(e2, traceback=True)) 296 295 if isinstance(e, PermissionError): 297 296 raise HTTPForbidden(e) 298 297 if isinstance(e, ResourceNotFound):
comment:18 by , 8 years ago
That looks good. Changes committed to 1.2-stable in r15624, merged to trunk in r15625.
With:
-
trac/web/main.py
diff --git a/trac/web/main.py b/trac/web/main.py index 52a9c7ebf..3e112d172 100644
a b class RequestDispatcher(Component): 289 289 self.log.warning("Exception caught while post-processing" 290 290 " request: %s", exception_to_unicode(e2)) 291 291 except Exception as e2: 292 self.log.error("Exception caught while post-processing" 293 " request: %s", 294 exception_to_unicode(e2, traceback=True)) 292 if type(e) is type(e2) and e.args == e2.args: 293 self.log.warning("Exception caught while post-processing" 294 " request: %s", exception_to_unicode(e2)) 295 else: 296 self.log.error("Exception caught while post-processing" 297 " request: %s", 298 exception_to_unicode(e2, traceback=True)) 295 299 if isinstance(e, PermissionError): 296 300 raise HTTPForbidden(e) 297 301 if isinstance(e, ResourceNotFound):
the following will be logged:
22:34:37 Trac[main] WARNING: Exception caught while post-processing request: HTTPNotFound: 404 Not Found (Invalid URL encoding (was '/milestone/\xad')) 22:34:37 Trac[main] WARNING: [127.0.0.1] HTTPNotFound: 404 Not Found (Invalid URL encoding (was '/milestone/\xad')), <RequestWithSession "GET '/milestone/\xad'">, referrer None
With:
-
trac/web/main.py
diff --git a/trac/web/main.py b/trac/web/main.py index 52a9c7ebf..0ec782c8f 100644
a b class RequestDispatcher(Component): 289 289 self.log.warning("Exception caught while post-processing" 290 290 " request: %s", exception_to_unicode(e2)) 291 291 except Exception as e2: 292 self.log.error("Exception caught while post-processing" 293 " request: %s", 294 exception_to_unicode(e2, traceback=True)) 292 if not (type(e) is type(e2) and e.args == e2.args): 293 self.log.error("Exception caught while post-processing" 294 " request: %s", 295 exception_to_unicode(e2, traceback=True)) 295 296 if isinstance(e, PermissionError): 296 297 raise HTTPForbidden(e) 297 298 if isinstance(e, ResourceNotFound):
logging will be:
22:37:17 Trac[main] WARNING: [127.0.0.1] HTTPNotFound: 404 Not Found (Invalid URL encoding (was '/milestone/\xad')), <RequestWithSession "GET '/milestone/\xad'">, referrer None
Is the latter patch good enough?
Or:
trac/web/main.py