Skip to content

Random errors on MD5 auth with pgbouncer #49

New issue

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

By clicking “No 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? No Sign in to your account

Closed
vharitonsky opened this issue Dec 14, 2016 · 8 comments
Closed

Random errors on MD5 auth with pgbouncer #49

vharitonsky opened this issue Dec 14, 2016 · 8 comments

Comments

@vharitonsky
Copy link

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()
@vharitonsky vharitonsky changed the title Random errors on MD auth with pgbouncer Random errors on MD5 auth with pgbouncer Dec 15, 2016
@elprans
Copy link
Member

elprans commented Dec 16, 2016

Can you reproduce this on direct connections to PostgreSQL server? This might be a pgbouncer bug.

@vharitonsky
Copy link
Author

I also could not reproduce it locally, maybe production setup bug

@vharitonsky
Copy link
Author

But maybe there is a workaround?

@elprans
Copy link
Member

elprans commented Dec 21, 2016

I don't think we can do anything about this. I'll close this issue now, but feel free to reopen if you can reproduce without pgbouncer in the mix.

As a workaround I would suggest to continue doing what you are doing, maybe with a retry counter.

@AmatanHead
Copy link
Contributor

I'm experiencing the same error. And I can't reproduce it without pgbouncer. @vharitonsky, were you able to figure it out?

@elprans
Copy link
Member

elprans commented Oct 5, 2017

This actually seems to be a duplicate of #158, which is fixed in master.

@AmatanHead
Copy link
Contributor

Indeed it is, thanks.

@Azim0313
Copy link

Azim0313 commented May 9, 2018

Hi elprans,

This is a closed issue, but did you guys got any update for any possible solution. We actually need a rca for this in our company. We sometimes get this issue on our production and its raising concern. Please guide.

Cheers,
TripleA

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

No branches or pull requests

4 participants