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

Bad file descriptor (src/epoll.cpp:100) #1276

Closed
calio opened this issue Mar 26, 2019 · 4 comments
Closed

Bad file descriptor (src/epoll.cpp:100) #1276

calio opened this issue Mar 26, 2019 · 4 comments

Comments

@calio
Copy link

calio commented Mar 26, 2019

Complete example

import sys
import os
import zmq
import logging
import socket
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)

class Connection():
    def __init__(self, handle):
        sock_type, dest_addr = handle
        self.sock_type = sock_type
        self.dest_addr = dest_addr

        context = zmq.Context()
        self._handle = context.socket(self.sock_type)
        logger.debug("recreate zmq socket {}".format(self.sock_type))
        self._handle.connect(self.dest_addr)
        logger.debug("connect to zmq {}".format(self.dest_addr))

    def send(self, buf):
        """Send a (picklable) object"""
        self._handle.send(buf)

def foo(reader):
    print("subprocess", vars(reader))
    data = b"GET"
    reader.send(data)

def _main():
    s = socket.socket()
    fd = s.fileno()
    with os.fdopen(fd, 'rb', closefd=True):
        fc = Connection((3, "tcp://172.17.0.1:65535"))
    return foo(fc)

exitcode = _main()
sys.exit(exitcode)

Expected behavior

Code exit normally

Actual behavior

Core dump

$ python zmq_bug_client.py                                                                                                
subprocess {'sock_type': 3, 'dest_addr': 'tcp://172.17.0.1:65535', '_handle': <zmq.sugar.socket.Socket object at 0x7fb8f17548d0>}
Bad file descriptor (src/epoll.cpp:100)
[2]    13011 abort (core dumped)  python zmq_bug_client.py

System info

$ pip freeze
adal==1.2.1
asn1crypto==0.24.0
atomicwrites==1.2.1
attrs==18.2.0
autopep8==1.4.3
cachetools==3.1.0
certifi==2018.11.29
cffi==1.12.2
chardet==3.0.4
cloudpickle==0.8.0
cryptography==2.6.1
docker==3.7.0
docker-pycreds==0.4.0
entrypoints==0.3
flake8==3.7.7
google-auth==1.6.3
idna==2.8
kubernetes==8.0.1
mccabe==0.6.1
more-itertools==5.0.0
netifaces==0.10.9
numpy==1.16.2
oauthlib==3.0.1
pluggy==0.8.1
psutil==5.5.1
py==1.7.0
pyasn1==0.4.5
pyasn1-modules==0.2.4
pycodestyle==2.5.0
pycparser==2.19
pyflakes==2.1.1
PyJWT==1.7.1
pytest==4.2.0
python-dateutil==2.8.0
PyYAML==3.13
pyzmq==18.0.1
requests==2.21.0
requests-oauthlib==1.2.0
rsa==4.0
six==1.12.0
urllib3==1.24.1
websocket-client==0.54.0
zmq==0.0.0
$ python --version
Python 3.6.7
$ uname -a
Linux *** 4.15.0-46-generic #49-Ubuntu SMP Wed Feb 6 09:33:07 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
$ gcc --version
gcc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@minrk
Copy link
Member

minrk commented Mar 26, 2019

I believe this is all in the randomized order in which objects are cleaned up in recent versions of Python 3, which can mean that zmq objects get deleted in the wrong order. If you close sockets explicitly, e.g. by calling self._handle.close() in a Connection.close() method, this shouldn't come up.

@blackCmd
Copy link

Complete example

import sys
import os
import zmq
import logging
import socket
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)

class Connection():
    def __init__(self, handle):
        sock_type, dest_addr = handle
        self.sock_type = sock_type
        self.dest_addr = dest_addr

        context = zmq.Context()
        self._handle = context.socket(self.sock_type)
        logger.debug("recreate zmq socket {}".format(self.sock_type))
        self._handle.connect(self.dest_addr)
        logger.debug("connect to zmq {}".format(self.dest_addr))

    def send(self, buf):
        """Send a (picklable) object"""
        self._handle.send(buf)

def foo(reader):
    print("subprocess", vars(reader))
    data = b"GET"
    reader.send(data)

def _main():
    s = socket.socket()
    fd = s.fileno()
    with os.fdopen(fd, 'rb', closefd=True):
        fc = Connection((3, "tcp://172.17.0.1:65535"))
    return foo(fc)

exitcode = _main()
sys.exit(exitcode)

Expected behavior

Code exit normally

Actual behavior

Core dump

$ python zmq_bug_client.py                                                                                                
subprocess {'sock_type': 3, 'dest_addr': 'tcp://172.17.0.1:65535', '_handle': <zmq.sugar.socket.Socket object at 0x7fb8f17548d0>}
Bad file descriptor (src/epoll.cpp:100)
[2]    13011 abort (core dumped)  python zmq_bug_client.py

System info

$ pip freeze
adal==1.2.1
asn1crypto==0.24.0
atomicwrites==1.2.1
attrs==18.2.0
autopep8==1.4.3
cachetools==3.1.0
certifi==2018.11.29
cffi==1.12.2
chardet==3.0.4
cloudpickle==0.8.0
cryptography==2.6.1
docker==3.7.0
docker-pycreds==0.4.0
entrypoints==0.3
flake8==3.7.7
google-auth==1.6.3
idna==2.8
kubernetes==8.0.1
mccabe==0.6.1
more-itertools==5.0.0
netifaces==0.10.9
numpy==1.16.2
oauthlib==3.0.1
pluggy==0.8.1
psutil==5.5.1
py==1.7.0
pyasn1==0.4.5
pyasn1-modules==0.2.4
pycodestyle==2.5.0
pycparser==2.19
pyflakes==2.1.1
PyJWT==1.7.1
pytest==4.2.0
python-dateutil==2.8.0
PyYAML==3.13
pyzmq==18.0.1
requests==2.21.0
requests-oauthlib==1.2.0
rsa==4.0
six==1.12.0
urllib3==1.24.1
websocket-client==0.54.0
zmq==0.0.0
$ python --version
Python 3.6.7
$ uname -a
Linux *** 4.15.0-46-generic #49-Ubuntu SMP Wed Feb 6 09:33:07 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
$ gcc --version
gcc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Plz... help me.
I encounter this error on a specific computer..

@DACHOPRA
Copy link

I am facing the same issue for Win32/x86 CPP build on Windows 10 system.

@blackCmd
Copy link

blackCmd commented Aug 22, 2021

I am facing the same issue for Win32/x86 CPP build on Windows 10 system.

Hi, change version. I solved it.
Win64 VS16 build.

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

4 participants