Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Matrix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Operate
Environments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Matrix
Commits
77794ebc
Unverified
Commit
77794ebc
authored
4 years ago
by
Richard van der Hoff
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix stack overflow when logging system encounters an error (#8268)
parent
7586fdf1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
changelog.d/8268.bugfix
+1
-0
1 addition, 0 deletions
changelog.d/8268.bugfix
synapse/config/logger.py
+23
-2
23 additions, 2 deletions
synapse/config/logger.py
with
24 additions
and
2 deletions
changelog.d/8268.bugfix
0 → 100644
+
1
−
0
View file @
77794ebc
Fix stack overflow when stderr is redirected to the logging system, and the logging system encounters an error.
This diff is collapsed.
Click to expand it.
synapse/config/logger.py
+
23
−
2
View file @
77794ebc
...
...
@@ -17,6 +17,7 @@ import logging
import
logging.config
import
os
import
sys
import
threading
from
string
import
Template
import
yaml
...
...
@@ -25,6 +26,7 @@ from twisted.logger import (
ILogObserver
,
LogBeginner
,
STDLibLogObserver
,
eventAsText
,
globalLogBeginner
,
)
...
...
@@ -216,8 +218,9 @@ def _setup_stdlib_logging(config, log_config, logBeginner: LogBeginner):
# system.
observer
=
STDLibLogObserver
()
def
_log
(
event
):
threadlocal
=
threading
.
local
()
def
_log
(
event
):
if
"
log_text
"
in
event
:
if
event
[
"
log_text
"
].
startswith
(
"
DNSDatagramProtocol starting on
"
):
return
...
...
@@ -228,7 +231,25 @@ def _setup_stdlib_logging(config, log_config, logBeginner: LogBeginner):
if
event
[
"
log_text
"
].
startswith
(
"
Timing out client
"
):
return
return
observer
(
event
)
# this is a workaround to make sure we don't get stack overflows when the
# logging system raises an error which is written to stderr which is redirected
# to the logging system, etc.
if
getattr
(
threadlocal
,
"
active
"
,
False
):
# write the text of the event, if any, to the *real* stderr (which may
# be redirected to /dev/null, but there's not much we can do)
try
:
event_text
=
eventAsText
(
event
)
print
(
"
logging during logging: %s
"
%
event_text
,
file
=
sys
.
__stderr__
)
except
Exception
:
# gah.
pass
return
try
:
threadlocal
.
active
=
True
return
observer
(
event
)
finally
:
threadlocal
.
active
=
False
logBeginner
.
beginLoggingTo
([
_log
],
redirectStandardIO
=
not
config
.
no_redirect_stdio
)
if
not
config
.
no_redirect_stdio
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment