Error: LoggingContext must be given either a name or a parent context
Describe the bug
When using this storage provider with Synapse 1.34.0 it sometimes throws the following error:
builtins.ValueError: LoggingContext must be given either a name or a parent context
To Reproduce Steps to reproduce the behavior:
- Update/Install synapse 1.34.0
- Install & configure this storage-provider
- Take a look onto your logs...
- See error
Additional context The following is the experpt with the error from synapse's log:
2021-05-19 20:24:54,886 - twisted - 258 - CRITICAL - sentinel - Unhandled Error
Traceback (most recent call last):
File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/synapse/app/_base.py", line 123, in run
run_command()
File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/twisted/internet/base.py", line 1283, in run
self.mainLoop()
File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/twisted/internet/base.py", line 1295, in mainLoop
self.doIteration(t)
File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/twisted/internet/epollreactor.py", line 235, in doPoll
log.callWithLogger(selectable, _drdw, selectable, fd, event)
--- <exception caught here> ---
File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/twisted/python/log.py", line 103, in callWithLogger
return callWithContext({"system": lp}, func, *args, **kw)
File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/twisted/python/log.py", line 86, in callWithContext
return context.call({ILogContext: newCtx}, func, *args, **kw)
File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/twisted/python/context.py", line 122, in callWithContext
return self.currentContext().callWithContext(ctx, func, *args, **kw)
File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/twisted/python/context.py", line 85, in callWithContext
return func(*args,**kw)
File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/twisted/internet/posixbase.py", line 627, in _doReadOrWrite
self._disconnectSelectable(selectable, why, inRead)
File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/twisted/internet/posixbase.py", line 252, in _disconnectSelectable
selectable.readConnectionLost(f)
File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/twisted/internet/tcp.py", line 307, in readConnectionLost
self.connectionLost(reason)
File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/twisted/internet/tcp.py", line 321, in connectionLost
abstract.FileDescriptor.connectionLost(self, reason)
File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/twisted/internet/abstract.py", line 205, in connectionLost
self.producer.stopProducing()
File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/twisted/web/http.py", line 2610, in stopProducing
self._requestProducer.stopProducing()
File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/s3_storage_provider.py", line 296, in stopProducing
with LoggingContext():
File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/synapse/logging/context.py", line 322, in __init__
"LoggingContext must be given either a name or a parent context"
builtins.ValueError: LoggingContext must be given either a name or a parent context
The fix here is to give the LoggingContext() on line 296 a name
The problem in question is now at line 314
The code with the problem is :
def stopProducing(self):
"""See IPushProducer.stopProducing
"""
# The consumer wants no more data ever, signal _S3DownloadThread
self.stop_event.set()
self.wakeup_event.set()
if not self.deferred.called:
with LoggingContext():
self.deferred.errback(Exception("Consumer ask to stop producing"))
I'm not really sure what that with LoggingContext(): line is doing anyway. self.deferred is expected to run its callbacks with no logging context (which is why it is wrapped in make_deferred_yieldable), so why are we creating a LoggingContext for it?
It appears to have been introduced (by me :roll_eyes: ) in https://github.com/matrix-org/synapse-s3-storage-provider/pull/30/commits/ea021c25b86a7dd85e9289951538b87d9ec7e634, but there are no clues there.
I think the fix is just to remove the with LoggingContext(): line.
So is the solution to just remove with LoggingContext():? This is generating quite a bit of spam in the homeserver logs.
So is the solution to just remove
with LoggingContext():?
I think the fix is just to remove the
with LoggingContext():line.
still on 1.98.0