Skip to content

self._write_ready() 'NoneType' object is not callable #3546

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

Open
aelamran opened this issue Mar 6, 2025 · 3 comments
Open

self._write_ready() 'NoneType' object is not callable #3546

aelamran opened this issue Mar 6, 2025 · 3 comments

Comments

@aelamran
Copy link

aelamran commented Mar 6, 2025

 Traceback (most recent call last):
  File "/backend/src/services/redis_service.py", line 94, in get_cached_profiles
    fetched_profiles = await self.client.json().mget(keys, Path.root_path())
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.12/site-packages/redis/asyncio/client.py", line 616, in execute_command
    return await conn.retry.call_with_retry(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.12/site-packages/redis/asyncio/retry.py", line 59, in call_with_retry
    return await do()
           ^^^^^^^^^^
  File "/opt/venv/lib/python3.12/site-packages/redis/asyncio/client.py", line 589, in _send_command_parse_response
    await conn.send_command(*args)
  File "/opt/venv/lib/python3.12/site-packages/redis/asyncio/connection.py", line 505, in send_command
    await self.send_packed_command(
  File "/opt/venv/lib/python3.12/site-packages/redis/asyncio/connection.py", line 480, in send_packed_command
    self._writer.writelines(command)
  File "/usr/local/lib/python3.12/asyncio/streams.py", line 349, in writelines
    self._transport.writelines(data)
  File "/usr/local/lib/python3.12/asyncio/selector_events.py", line 1182, in writelines
    self._write_ready()
TypeError: 'NoneType' object is not callable 

I am experiencing this issue especially in peak traffic.

My redis service is initialized this way:

import redis.asyncio as redis
@lru_cache()
def get_redis_pool():
    settings = get_settings()
    return redis.ConnectionPool.from_url(settings.REDIS_URL_WITH_PASSWORD, decode_responses=True)


@lru_cache()
def get_redis_client():
    redis_pool = get_redis_pool()
    client = redis.Redis(connection_pool=redis_pool)
    return client


# Dependency to create RedisService
async def get_redis_service(
    redis_client: redis.Redis = Depends(get_redis_client),
    firestore_db: firestore.AsyncClient = Depends(get_firestore_db),
):
    from src.services.redis_service import RedisService

    return RedisService(redis_client, firestore_db)

Am I missing something in my redis client?

I saw an issue similar to this here but upgrading python to 3.12.9 didn't help.

python 3.12.9
redis 5.2.1

@vladvildanov
Copy link
Collaborator

@aelamran Hi, I think there might be an issue in which client are you using sync or async? There might be an issue if you're trying to use async client outside of running event loop which lead to the fact that some references are None.

Please check whether you creating a correct instance of client

@aelamran
Copy link
Author

aelamran commented Mar 7, 2025

@aelamran Hi, I think there might be an issue in which client are you using sync or async? There might be an issue if you're trying to use async client outside of running event loop which lead to the fact that some references are None.

Please check whether you creating a correct instance of client

Sorry, I shared how I am setting my client without sharing the module import, it's indeed async:
import redis.asyncio as redis

@anuraag-khare
Copy link

Hey @aelamran , I am facing the same issues, it happens randomly so can’t properly reproduce it. Did you find any solutions?

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

No branches or pull requests

3 participants