supabase-py: Frequent httpx.RemoteProtocolError: Server disconnected

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

When making API requests to Supabase using PostgREST client, the server unexpectedly disconnects, resulting in a httpx.RemoteProtocolError: Server disconnected error. This happens intermittently when trying to retrieve data from a specific table or batch insert.

To Reproduce

Steps to reproduce the behavior:

  1. Set up a connection to Supabase using client
  2. Attempt to execute a query to retrieve data from a table
  3. The server disconnects during the request, throwing a RemoteProtocolError

Code snippet demonstrating the issue:

# Using postgrest client to query a table
result = client.table("my_table").select("*").eq("key", "value").execute()
# This results in server disconnection

Expected behavior

The query should complete successfully and return the requested data without any server disconnection.

System information

  • OS: Linux
  • Version of postgrest-py: [latest]
  • Version of httpx: [latest]
  • Python version: 3.11

Additional context

As of now, We have added retry mechanism over certain call during exception of HTTPX disconnect. Following stack trace,

  File "/usr/local/lib/python3.11/site-packages/postgrest/_sync/request_builder.py", line 58, in execute
    r = self.session.request(
        ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 825, in request
    return self.send(request, auth=auth, follow_redirects=follow_redirects)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/dd_tracer/python/ddtrace/contrib/internal/httpx/patch.py", line 166, in _wrapped_sync_send
    resp = wrapped(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 914, in send
    response = self._send_handling_auth(
               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 942, in _send_handling_auth
    response = self._send_handling_redirects(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 979, in _send_handling_redirects
    response = self._send_single_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 1014, in _send_single_request
    response = transport.handle_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/httpx/_transports/default.py", line 249, in handle_request
    with map_httpcore_exceptions():
  File "/usr/local/lib/python3.11/contextlib.py", line 155, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/usr/local/lib/python3.11/site-packages/httpx/_transports/default.py", line 118, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.RemoteProtocolError: Server disconnected

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 1
  • Comments: 15 (5 by maintainers)

Most upvoted comments

As of 2.16.0, you can now pass your own httpx client to the library. You can configure different settings and see which works best in your server setup.

from httpx import Client, HTTPTransport, Limits
from supabase import create_client, ClientOptions

transport = HTTPTransport(
    retries=3,
    http2=True,
    limits=Limits(
        max_connections=100,
        max_keepalive_connections=1,
        keepalive_expiry=None,
    )
)

with Client(transport=transport) as http_client:
    # Create a client with the custom httpx client
    options = ClientOptions(httpx_client=http_client)

    client = create_client(supabase_url, supabase_key, options=options)

Also encountered the same issue. With intermittent disconnection issues that are consistently triggering lately and can be isolated to supabase api calls. Also no logs/errors in Supabase logs. Using supabase python client (2.4.0).

@silentworks in case it helps, we don’t see corresponding “disconnection” errors or anything anomalous in the Supabase logs (we’ve checked API gateway logs and Database logs). This is now frequently happening on another Supabase DB we use.

We did upgrade to the latest supabase-py (2.13.0) a couple of weeks ago. Prior to that we had been on 2.11.0.

I also encountered the same issue. I am using Python 3.11 and the latest supabase-py. I have a cron job in Kubernetes that periodically fetches some data. It works fine 99% of the time, but occasionally, this error occurs.