-
Notifications
You must be signed in to change notification settings - Fork 435
Closed
Description
I am connecting to the same pgbouncer with the the same credentials like a hundred times per second and sometimes I have this error:
File "/usr/local/lib/python3.5/dist-packages/asyncpg/connection.py", line 558, in connect
await connected
File "uvloop/future.pyx", line 241, in __await__ (uvloop/loop.c:94875)
File "uvloop/task.pyx", line 186, in uvloop.loop.BaseTask._fast_wakeup (uvloop/loop.c:100074)
File "uvloop/future.pyx", line 101, in uvloop.loop.BaseFuture._result_impl (uvloop/loop.c:93110)
asyncpg.exceptions.ProtocolViolationError: Auth failed
Switching to plain auth in pgbouncer fixes the error. I suspect that something in salt is causing the issue, like some cruft in the buffer or leftover message that is not fully read:
elif status == AUTH_REQUIRED_PASSWORDMD5:
# AuthenticationMD5Password
# Note: MD5 salt is passed as a four-byte sequence
md5_salt = cpython.PyBytes_FromStringAndSize(
self.buffer.read_bytes(4), 4)
self.auth_msg = self._auth_password_message_md5(md5_salt)
Simple retry will lower the number of these errors significantly:
try:
con = await connect(
self.dsn,
timeout=self.timeout,
command_timeout=self.timeout,
)
except ProtocolViolationError:
con = await connect(
self.dsn,
timeout=self.timeout,
command_timeout=self.timeout,
)
But maybe there is a cleaner solution? Maybe the connection is not closed properly or some buffer was not flushed here:
row = await con.fetchrow(fetch_image_query, int(file_id), name)
await con.close()