ValueError: filedescriptor out of range in select()

Discussion in 'Python' started by Laszlo Nagy, Mar 17, 2009.

  1. Laszlo Nagy

    Laszlo Nagy Guest

    This is a long running process, written in Python. Only standard lib is
    used. This process accepts connections on TCP sockets, read/write data.

    After about one day, it starts throwing this when I try to connect:

    2009-03-17 09:49:50,096 INFO .accesspoint0 ('127.0.0.1', 55510) connecting
    2009-03-17 09:49:50,097 ERROR .accesspoint0 Traceback (most recent call
    last):
    File
    "/usr/local/www/vhosts/shopzeus.com/fantasy/sorb/accesspoints/srvtcp.py",
    line 34, in handle_request
    t = sorb.endpoint.SocketEndpoint(conn,self.router)
    File "/usr/local/www/vhosts/shopzeus.com/fantasy/sorb/endpoint.py",
    line 304, in __init__
    StreamEndpoint.__init__(self,router)
    File "/usr/local/www/vhosts/shopzeus.com/fantasy/sorb/endpoint.py",
    line 133, in __init__
    self.format = self.read_str() # determine remote format
    File "/usr/local/www/vhosts/shopzeus.com/fantasy/sorb/endpoint.py",
    line 236, in read_str
    size = self.read_long()
    File "/usr/local/www/vhosts/shopzeus.com/fantasy/sorb/endpoint.py",
    line 222, in read_long
    return struct.unpack(">q",self.read_data(8))[0]
    File "/usr/local/www/vhosts/shopzeus.com/fantasy/sorb/endpoint.py",
    line 344, in read_data
    ready = select.select([fd], [], [], 0.2)
    ValueError: filedescriptor out of range in select()


    The code for read_data:

    def read_data(self,size):
    res = ""
    fd = self.socket.fileno()
    while not self.stop_requested.isSet():
    remaining = size - len(res)
    if remaining<=0:
    break
    # Give one second for an incoming connection so we can stop the
    # server in seconds when needed
    ready = select.select([fd], [], [], 0.2)
    if fd in ready[0]:
    data = self.socket.recv(min(remaining,8192)) # 8192 is
    recommended by socket.socket manual.
    if not data:
    # select returns the fd but there is no data to read
    -> connection closed!
    self.shutdown()
    raise TransportClosedError("Connection closed.")
    else:
    res += data
    else:
    pass
    if self.stop_requested.isSet():
    self.shutdown()
    raise TransportClosedError()
    return res


    If I telnet this server this is what I see:

    Trying 127.0.0.1...
    Connected to localhost.
    Escape character is '^]'.
    Connection closed by foreign host.


    E.g. the connection is closed instantly after the connection has been
    made. For some reason, the client socket on the server side has an
    invalid fileno, and it cannot be passed to select.select(). I found some
    articles on the internet about this error, but nothing useful about how
    to solve it.

    Please help.

    Laszlo
    Laszlo Nagy, Mar 17, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paolo Invernizzi

    filedescriptor out of range in select()

    Paolo Invernizzi, Jun 26, 2003, in forum: Python
    Replies:
    0
    Views:
    898
    Paolo Invernizzi
    Jun 26, 2003
  2. Andrew Bennetts

    Re: filedescriptor out of range in select()

    Andrew Bennetts, Jun 26, 2003, in forum: Python
    Replies:
    5
    Views:
    5,062
    Paolo Invernizzi
    Jun 30, 2003
  3. Laszlo Nagy
    Replies:
    0
    Views:
    435
    Laszlo Nagy
    Mar 17, 2009
  4. k3xji
    Replies:
    5
    Views:
    708
    Steven D'Aprano
    Sep 16, 2010
  5. Isaac Won
    Replies:
    0
    Views:
    198
    Isaac Won
    Feb 6, 2013
Loading...

Share This Page