tlocke / pg8000

A Pure-Python PostgreSQL Driver
BSD 3-Clause "New" or "Revised" License
515 stars 46 forks source link

Fixing the pg8000 since it can't connect to AWS RDS Proxy #72

Closed grepit closed 3 years ago

grepit commented 3 years ago

why:a pg8000 does not work when AWS RDS proxy is used. There is stackoverlow about this https://stackoverflow.com/questions/67242059/aws-rds-proxy-error-postgres-rds-proxy-currently-doesn-t-support-command-lin what: we tested this in our lambda using AWS RDS Proxy and pg8000 and simple solution was chaning two line of code in core.py

tlocke commented 3 years ago

That's fantastic work @grepit, thanks for tracking it down. I changed the code slightly from your original patch, but it should achieve the same result. I've done a new release 1.19.4, let me know if that doesn't work for you.

grepit commented 3 years ago

great thanks Tony 👍

jadenyjw commented 3 years ago

Still timing out for me using 1.19.4, the original commit by @grepit works for me.

tlocke commented 3 years ago

Interesting. I don't have access to AWS, so can you narrow down what's going wrong? It seems that it doesn't like the FLUSH message sent after the PASSWORD message. Thanks for any info you can provide!

@grepit does version 1.19.4 work for you?

grepit commented 3 years ago

1.19.4 does not actually work , we ended up using the changed I first did CR (i.e. core.py FLUSH )

tlocke commented 3 years ago

Well that's baffling. I can't see why there would be a difference between @grepit's patch and 1.19.4. As I say, I don't have access to AWS, so if there's any way anyone can narrow down the problem that would be great!

kyri-petrou commented 3 years ago

I've been having the same issue using pg8000 with an RDS Proxy. I found that setting ssl_context = True solves it. Any idea why this would be the case?

kukushking commented 3 years ago

@kyri-petrou Does your proxy enforce TLS? That could explain it.

If that's the case you'd have to create SSL context and supply it with RDS certificates like below:

import ssl
import pg8000

capath = "./rds-combined-ca-bundle.pem"
ssl_context = ssl.create_default_context(capath=capath)

pg8000.connect(..., ssl_context=ssl_context)
kyri-petrou commented 3 years ago

@kukushking apologies for not getting back to you sooner with this.

Long story short, I've managed to trace the issue down to a networking issue. Weirdly enough, the issue seemed to happen on every 2nd query when I was not using an SSL context, and once in a few hundreds when using one. Still not sure why, but that's not related to this discussion.

@tlocke thanks for looking into the issue and I really apologise if I sent you down a wild goose chase with my comment above

tlocke commented 3 years ago

This seems to be resolved now, but please feel free to re-open if it's still a problem.