reflex-dev / reflex

🕸️ Web apps in pure Python 🐍
https://reflex.dev
Apache License 2.0
19.85k stars 1.14k forks source link

[REF-2978] Redis CONFIG command disabled in AWS ElastiCache #3371

Closed sebastianjanisch closed 4 months ago

sebastianjanisch commented 5 months ago

Describe the bug When supplying a REDIS url to reflex where the URL points to an AWS ElastiCache instance the backend server fails when it tries to use the CONFIG command which is restricted for AWS ElastiCache.

Exception thrown:

File "/root/.cache/pypoetry/virtualenvs/bayesline-reflexgui-_BFE_qi0-py3.11/lib/python3.11/site-packages/reflex/state.py", line 1954, in __aenter__
--
05/22 14:52:43 | bayesline-reflexgui | Version: 23 | mutable_state = await self._self_actx.__aenter__()
05/22 14:52:43 | bayesline-reflexgui | Version: 23 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
05/22 14:52:43 | bayesline-reflexgui | Version: 23 | File "/usr/local/lib/python3.11/contextlib.py", line 210, in __aenter__
05/22 14:52:43 | bayesline-reflexgui | Version: 23 | return await anext(self.gen)
05/22 14:52:43 | bayesline-reflexgui | Version: 23 | ^^^^^^^^^^^^^^^^^^^^^
05/22 14:52:43 | bayesline-reflexgui | Version: 23 | File "/root/.cache/pypoetry/virtualenvs/bayesline-reflexgui-_BFE_qi0-py3.11/lib/python3.11/site-packages/reflex/app.py", line 994, in modify_state
05/22 14:52:43 | bayesline-reflexgui | Version: 23 | async with self.state_manager.modify_state(token) as state:
05/22 14:52:43 | bayesline-reflexgui | Version: 23 | File "/usr/local/lib/python3.11/contextlib.py", line 210, in __aenter__
05/22 14:52:43 | bayesline-reflexgui | Version: 23 | return await anext(self.gen)
05/22 14:52:43 | bayesline-reflexgui | Version: 23 | ^^^^^^^^^^^^^^^^^^^^^
05/22 14:52:43 | bayesline-reflexgui | Version: 23 | File "/root/.cache/pypoetry/virtualenvs/bayesline-reflexgui-_BFE_qi0-py3.11/lib/python3.11/site-packages/reflex/state.py", line 2543, in modify_state
05/22 14:52:43 | bayesline-reflexgui | Version: 23 | async with self._lock(token) as lock_id:
05/22 14:52:43 | bayesline-reflexgui | Version: 23 | File "/usr/local/lib/python3.11/contextlib.py", line 210, in __aenter__
05/22 14:52:43 | bayesline-reflexgui | Version: 23 | return await anext(self.gen)
05/22 14:52:43 | bayesline-reflexgui | Version: 23 | ^^^^^^^^^^^^^^^^^^^^^
05/22 14:52:43 | bayesline-reflexgui | Version: 23 | File "/root/.cache/pypoetry/virtualenvs/bayesline-reflexgui-_BFE_qi0-py3.11/lib/python3.11/site-packages/reflex/state.py", line 2629, in _lock
05/22 14:52:43 | bayesline-reflexgui | Version: 23 | await self._wait_lock(lock_key, lock_id)
05/22 14:52:43 | bayesline-reflexgui | Version: 23 | File "/root/.cache/pypoetry/virtualenvs/bayesline-reflexgui-_BFE_qi0-py3.11/lib/python3.11/site-packages/reflex/state.py", line 2591, in _wait_lock
05/22 14:52:43 | bayesline-reflexgui | Version: 23 | await self.redis.config_set(
05/22 14:52:43 | bayesline-reflexgui | Version: 23 | File "/root/.cache/pypoetry/virtualenvs/bayesline-reflexgui-_BFE_qi0-py3.11/lib/python3.11/site-packages/redis/asyncio/client.py", line 612, in execute_command
05/22 14:52:43 | bayesline-reflexgui | Version: 23 | return await conn.retry.call_with_retry(
05/22 14:52:43 | bayesline-reflexgui | Version: 23 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
05/22 14:52:43 | bayesline-reflexgui | Version: 23 | File "/root/.cache/pypoetry/virtualenvs/bayesline-reflexgui-_BFE_qi0-py3.11/lib/python3.11/site-packages/redis/asyncio/retry.py", line 59, in call_with_retry
05/22 14:52:43 | bayesline-reflexgui | Version: 23 | return await do()
05/22 14:52:43 | bayesline-reflexgui | Version: 23 | ^^^^^^^^^^
05/22 14:52:43 | bayesline-reflexgui | Version: 23 | File "/root/.cache/pypoetry/virtualenvs/bayesline-reflexgui-_BFE_qi0-py3.11/lib/python3.11/site-packages/redis/asyncio/client.py", line 586, in _send_command_parse_response
05/22 14:52:43 | bayesline-reflexgui | Version: 23 | return await self.parse_response(conn, command_name, **options)
05/22 14:52:43 | bayesline-reflexgui | Version: 23 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
05/22 14:52:43 | bayesline-reflexgui | Version: 23 | File "/root/.cache/pypoetry/virtualenvs/bayesline-reflexgui-_BFE_qi0-py3.11/lib/python3.11/site-packages/redis/asyncio/client.py", line 633, in parse_response
05/22 14:52:43 | bayesline-reflexgui | Version: 23 | response = await connection.read_response()
05/22 14:52:43 | bayesline-reflexgui | Version: 23 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
05/22 14:52:43 | bayesline-reflexgui | Version: 23 | File "/root/.cache/pypoetry/virtualenvs/bayesline-reflexgui-_BFE_qi0-py3.11/lib/python3.11/site-packages/redis/asyncio/connection.py", line 569, in read_response
05/22 14:52:43 | bayesline-reflexgui | Version: 23 | raise response from None
05/22 14:52:43 | bayesline-reflexgui | Version: 23 | redis.exceptions.ResponseError: unknown command 'CONFIG', with args beginning with: 'SET' 'notify-keyspace-events' 'Kgxe'

Quick googling I found this thread which explains that the CONFIG command is restricted. https://stackoverflow.com/questions/69656070/facing-redis-problem-unknown-command-config-with-args-beginning-with-set https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/SupportedCommands.html

To Reproduce Steps to reproduce the behavior:

Expected behavior A clear and concise description of what you expected to happen. A graceful handling of the condition that the CONFIG command cannot be used.

Screenshots If applicable, add screenshots to help explain your problem.

Below is the keyspace setup in AWS ElastiCache (maintained by Porter). image

Specifics (please complete the following information):

Additional context I'm reaching out to the folks from Porter to see what they can suggest. I presume the config setting still needs to be set but I don't understand enough about Redis.

REF-2978

masenf commented 5 months ago

Thanks for reporting this issue. First glance, i think we should be able to check the notify-keyspace-events setting and see if it's compatible with what reflex needs for pubsub and if not (and we can't set it ourselves), just raise an error. That way, if there is an alternative config mechanism (like the screenshot), then the user should still be able to run with it, provided they set the correct config manually.

sebastianjanisch commented 5 months ago

I'm checking with Porter to see how this might be manually configurable (right now I can't edit anything in AWS).

sebastianjanisch commented 5 months ago

@masenf I updated the parameters manually, see screenshot below. Is there a way to circumvent the error for now?

image

masenf commented 5 months ago

@sebastianjanisch it does not look possible to bypass the error at this point; but i can throw a PR up for next week's release