Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the right config section when starting the module #62

Merged
merged 1 commit into from
Oct 12, 2021

Conversation

babolivier
Copy link
Contributor

No description provided.

@babolivier babolivier requested a review from a team October 12, 2021 10:10
Copy link
Contributor

@squahtx squahtx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@@ -60,7 +60,7 @@ class S3StorageProviderBackend(StorageProvider):
"""

def __init__(self, hs, config):
self.cache_directory = hs.config.media_store_path
self.cache_directory = hs.config.media.media_store_path
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we might be able to delete this entirely, its only used in store_file as part of os.path.join, but the path store_file gets appears to be absolute already, so its pointless. I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

store_file seems to be called by Synapse

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

store_file's path appears to be relative to me, or am I mistaken?
https://github.com/matrix-org/synapse/blob/develop/synapse/rest/media/v1/media_storage.py#L159

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, yes, I misread that fname is the absolute path. Annoying.

@babolivier babolivier merged commit fd1e123 into main Oct 12, 2021
@babolivier babolivier deleted the babolivier/fix_config branch October 12, 2021 10:14
@patrickstump
Copy link

@babolivier , I know this is after the fact, but is there value to adding a version check since this popped up in v1.45.0? That is, if someone is running < v1.45.0 would it be required to use the previous call of self.cache_directory = hs.config.media_store_path ?

@babolivier
Copy link
Contributor Author

babolivier commented Oct 20, 2021

@babolivier , I know this is after the fact, but is there value to adding a version check since this popped up in v1.45.0? That is, if someone is running < v1.45.0 would it be required to use the previous call of self.cache_directory = hs.config.media_store_path ?

No, with Synapse < v1.45.0, reading hs.config.media.media_store_path still works.

@anoadragon453
Copy link
Member

@patrickstump For context we had a magic method which translated hs.config.media_store_path to hs.config.media.media_store_path. The method has now been removed, as it was a noticeable performance loss for minor developer convenience. But using the latter always worked 🙂

@richvdh
Copy link
Member

richvdh commented Oct 21, 2021

To be clear, is this fixing something that makes s3-storage-provider not work with newer versions of synapse? If so, what were the symptoms of the failure? Some sort of exception?

@babolivier
Copy link
Contributor Author

babolivier commented Oct 21, 2021

To be clear, is this fixing something that makes s3-storage-provider not work with newer versions of synapse? If so, what were the symptoms of the failure? Some sort of exception?

Yes, because media storage providers apparently get passed the Synapse config directly, and v1.45.0 removed the magic that translated hs.config.media_store_path into hs.config.media.media_store_path. This module was reading from hs.config.media_store_path, which raised an AttributeError and would prevent either "just" the media repository workers or the whole homeserver (if not using workers) from starting.

We should have caught this in matrix-org/synapse#10985 (comment), but forgot about the particular case of media storage providers.

@richvdh
Copy link
Member

richvdh commented Oct 21, 2021

ok, thanks Brendan.

As a reminder, it's very helpful to include an example of the error message, so that other people seeing the same error can search for it and find the fix.

@babolivier
Copy link
Contributor Author

Ah good point. Here's the full stacktrace:

Traceback (most recent call last):
  File "/home/synapse/src/synapse/app/_base.py", line 196, in wrapper
    await cb(*args, **kwargs)
  File "/home/synapse/src/synapse/app/_base.py", line 387, in start
    hs.start_listening()
  File "/home/synapse/src/synapse/app/generic_worker.py", line 389, in start_listening
    self._listen_http(listener)
  File "/home/synapse/src/synapse/app/generic_worker.py", line 325, in _listen_http
    media_repo = self.get_media_repository_resource()
  File "/home/synapse/src/synapse/server.py", line 185, in _get
    dep = builder(self)
  File "/home/synapse/src/synapse/server.py", line 615, in get_media_repository_resource
    return MediaRepositoryResource(self)
  File "/home/synapse/src/synapse/rest/media/v1/media_repository.py", line 986, in __init__
    media_repo = hs.get_media_repository()
  File "/home/synapse/src/synapse/server.py", line 185, in _get
    dep = builder(self)
  File "/home/synapse/src/synapse/server.py", line 619, in get_media_repository
    return MediaRepository(self)
  File "/home/synapse/src/synapse/rest/media/v1/media_repository.py", line 108, in __init__
    backend = clz(hs, provider_config)
  File "/home/synapse/synapse-s3-storage-provider/s3_storage_provider.py", line 63, in __init__
    self.cache_directory = hs.config.media_store_path
AttributeError: 'HomeServerConfig' object has no attribute 'media_store_path'

@HarHarLinks
Copy link

HarHarLinks commented Oct 21, 2021

@babolivier , I know this is after the fact, but is there value to adding a version check since this popped up in v1.45.0? That is, if someone is running < v1.45.0 would it be required to use the previous call of self.cache_directory = hs.config.media_store_path ?

No, with Synapse < v1.45.0, reading hs.config.media.media_store_path still works.

I upgraded synapse-s3-storage-provider together with synapse 1.45.1 using pip install --force-reinstall, but had to downgrade back to 1.43 (matrix-org/synapse#11049 (comment)). Now can't upload media, error log:

2021-10-21 12:17:51,904 - synapse.http.server - 93 - ERROR - POST-7488- Failed handle request via 'UploadResource': <XForwardedForRequest at 0x7f3bfbc62e20 method='POST' uri='/_matrix/media/r0/upload' clientproto='HTTP/1.0' site='8008'>
Traceback (most recent call last):
  File "site-packages/synapse/http/server.py", line 258, in _async_render_wrapper
    callback_return = await self._async_render(request)
  File "site-packages/synapse/http/server.py", line 286, in _async_render
    callback_return = await raw_callback_return
  File "site-packages/synapse/rest/media/v1/upload_resource.py", line 93, in _async_render_POST
    content_uri = await self.media_repo.create_content(
  File "site-packages/synapse/rest/media/v1/media_repository.py", line 169, in create_content
    fname = await self.media_storage.store_file(content, file_info)
  File "site-packages/synapse/rest/media/v1/media_storage.py", line 81, in store_file
    await self.write_to_file(source, f)
  File "site-packages/synapse/rest/media/v1/media_storage.py", line 88, in write_to_file
    await defer_to_thread(self.reactor, _write_file_synchronously, source, output)
  File "site-packages/twisted/python/threadpool.py", line 238, in inContext
    result = inContext.theWork()  # type: ignore[attr-defined]
  File "site-packages/twisted/python/threadpool.py", line 254, in <lambda>
    inContext.theWork = lambda: context.call(  # type: ignore[attr-defined]
  File "site-packages/twisted/python/context.py", line 118, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
  File "site-packages/twisted/python/context.py", line 83, in callWithContext
    return func(*args, **kw)
  File "site-packages/synapse/logging/context.py", line 902, in g
    return f(*args, **kwargs)
  File "site-packages/synapse/rest/media/v1/media_storage.py", line 298, in _write_file_synchronously
    source.seek(0)  # Ensure we read from the start of the file
ValueError: seek of closed file

So apparently this is not backwards compatible?

Also synapse.rest.media.v1._base - 256 - WARNING - GET-40201- Failed to write to consumer: <class 'Exception'> Consumer asked us to stop producing happens.

@callahad
Copy link

@HarHarLinks Can you please open a new issue, also if you could add the output of pip freeze and more log context around the error?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants