Skip to content
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

psycogreen breaks connect_timeout option #2

Closed
redlolgeerf opened this issue Nov 6, 2020 · 3 comments
Closed

psycogreen breaks connect_timeout option #2

redlolgeerf opened this issue Nov 6, 2020 · 3 comments

Comments

@redlolgeerf
Copy link

python version 3.8.6

library versions:
gevent==20.9.0
greenlet==0.4.17
psycogreen==1.0.2
psycopg2==2.8.6

minimal example:

import gevent
import gevent.monkey

gevent.monkey.patch_all()  # noqa

import psycogreen.gevent

psycogreen.gevent.patch_psycopg()  # noqa

import psycopg2


def fetch(num, secs):
    print("connecting to db")
    conn = psycopg2.connect("dbname=postgres connect_timeout=1")
    print("connected")


jobs = [gevent.spawn(fetch, 3, 2)]
gevent.joinall(jobs)

This will print "connecting to db" and hang. If you comment out line psycogreen.gevent.patch_psycopg() # noqa code will fail with OperationalError in couple seconds.

@redlolgeerf
Copy link
Author

Desired behavior can be achieved, if I replace psycogreen.gevent.patch_psycopg() with

from psycogreen.gevent import gevent_wait_callback
from psycopg2 import extensions
from functools import partial
extensions.set_wait_callback(partial(gevent_wait_callback, timeout=1))

Maybe, this should be added to documentation.

@dvarrazzo
Copy link
Member

Yes, I'm aware: in async mode the libpq doesn't respect the connect_timeout, it is the client which should re-implement it. So this is actually a psycopg2 problem. There might be a ticket open for it already... yup, this: psycopg/psycopg2#944

@redlolgeerf
Copy link
Author

Thanks, I'll close this issue then.

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

2 participants