From 2ea3ad9c22444f3d071412ea49449a787f243793 Mon Sep 17 00:00:00 2001 From: Yashwardhan Singh Date: Thu, 7 Jul 2016 05:40:34 -0700 Subject: [PATCH] greenio: makefile related pypy socket ref counting On PyPy `[Errno 9] Bad file descriptor` because `makefile dup/_drop` dance leaves socket with PyPy special reference counter zero, so it may be garbage collected. https://github.com/eventlet/eventlet/issues/318 (@temoto) maybe proper fix is to remove `dup` in `makefile()`. --- eventlet/greenio/base.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/eventlet/greenio/base.py b/eventlet/greenio/base.py index 5ed2593..847498d 100644 --- a/eventlet/greenio/base.py +++ b/eventlet/greenio/base.py @@ -299,6 +299,11 @@ class GreenSocket(object): res = _python2_fileobject(dupped, *args, **kwargs) if hasattr(dupped, "_drop"): dupped._drop() + # Making the close function of dupped None so that when garbage collector + # kicks in and tries to call del, which will ultimately call close, _drop + # doesn't get called on dupped twice as it has been already explicitly called in + # previous line + dupped.close = None return res def makeGreenFile(self, *args, **kw):