synapse-s3-storage-provider icon indicating copy to clipboard operation
synapse-s3-storage-provider copied to clipboard

Error: LoggingContext must be given either a name or a parent context

Open n0emis opened this issue 4 years ago • 5 comments

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:

  1. Update/Install synapse 1.34.0
  2. Install & configure this storage-provider
  3. Take a look onto your logs...
  4. 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

n0emis avatar May 20 '21 09:05 n0emis

The fix here is to give the LoggingContext() on line 296 a name

erikjohnston avatar May 27 '21 11:05 erikjohnston

The problem in question is now at line 314

richvdh avatar Apr 20 '22 12:04 richvdh

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.

richvdh avatar Apr 20 '22 12:04 richvdh

So is the solution to just remove with LoggingContext():? This is generating quite a bit of spam in the homeserver logs.

Sharparam avatar Aug 23 '22 09:08 Sharparam

So is the solution to just remove with LoggingContext():?

I think the fix is just to remove the with LoggingContext(): line.

richvdh avatar Aug 23 '22 14:08 richvdh

still on 1.98.0

nycterent avatar Jan 07 '24 09:01 nycterent