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

gevent seems to block redis forever with socket. getaddrinfo when used in multiprocessing #230

Closed
lxyu opened this issue Jan 7, 2013 · 11 comments

Comments

@lxyu
Copy link

lxyu commented Jan 7, 2013

I came into a problem recently, after tracing problem down, I got this code

# -*- coding: utf-8 -*-

import gevent.monkey
gevent.monkey.patch_all()

import socket
import redis
import multiprocessing


def block():
    print 'x'
    r = redis.Redis()
    r.get(1)
    print 'o'


socket.getaddrinfo('localhost', 8001)

p = multiprocessing.Process(target=block)
p.start()
p.join()

This code will be blocked forever in r.get(1).

If I comment out socket.getaddrinfo('localhost', 8001), it'll not be blocked.

So any idea on how to solve this?


Not clear of whether this is gevent problem or redis-py problem, so I also post this issue to redis:
redis/redis-py#310

@lxyu
Copy link
Author

lxyu commented Jan 7, 2013

btw, I'm using

gevent==1.0rc2
redis==2.7.2

@lxyu
Copy link
Author

lxyu commented Jan 8, 2013

ok, after some further search, add GEVENT_RESOLVER=block solve this problem.

@awestendorf
Copy link

Confirmed that I'm having this problem too and it's not anything to do with redis specifically, but any socket connection, including localhost. Not a problem on 1.0b1 which we're using, but is on 1.0rc2. Any place to start looking to help fix this bug?

@Anorov
Copy link

Anorov commented Jan 31, 2013

Is this a problem only when multiprocessing is in use?

@lxyu
Copy link
Author

lxyu commented Jan 31, 2013

Don't know if other situations will cause it.

In this case, it is.

@awestendorf
Copy link

I had been using native threads, not multiprocessing, though the lib was loaded in order to get the cpu count. The code in question is single threaded now and I'll give this a shot again. The place where it blocked was in the main thread on process init.

@jgehrcke
Copy link
Contributor

jgehrcke commented Feb 1, 2013

Naive forking via multiprocessing within a gevent-driven application is known to raise problems. With gipc this code works fine:

import gevent.monkey
gevent.monkey.patch_all()
import gipc
import socket
import redis

def block():
    print 'x'
    r = redis.Redis()
    r.get(1)
    print 'o'

s = socket.getaddrinfo("www.python.org", 80, 0, 0, socket.SOL_TCP)

p = gipc.start_process(target=block)
p.join()

@rayalan
Copy link

rayalan commented May 28, 2014

This problem also occurs when running gevent with uwsgi and the --master flag.

@evgenity
Copy link

evgenity commented Jul 3, 2014

The similar problem occurs for me when using grequest (gevent+request) and redis together. Any ideas about how to fix it?

@alternativshik
Copy link

Same problem, but with httplib2. socket.getaddrinfo() in httplib2 block forever

import os
os.environ['GEVENT_RESOLVER'] = 'ares'
resolve problem

@Anorov
Copy link

Anorov commented Nov 21, 2014

Perhaps a dumb question, but shouldn't c-ares be gevent's default resolver in the latest versions?

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

7 participants