Skip to content

ValueError: I/O operation on closed file #633

Closed
@hannosch

Description

@hannosch

Python 2.6, redis-py 2.10.3

During connection.disconnect I get a ValueError and the connection cleanup fails.

Traceback, with app specific first couple stackframes removed:

Stacktrace (most recent call last):
  ...
  File "redis/client.py", line 2578, in execute
    return execute(conn, stack, raise_on_error)
  File "redis/client.py", line 2447, in _execute_transaction
    connection.send_packed_command(all_cmds)
  File "redis/connection.py", line 543, in send_packed_command
    self.disconnect()
  File "redis/connection.py", line 519, in disconnect
    self._parser.on_disconnect()
  File "redis/connection.py", line 216, in on_disconnect
    self._buffer.close()
  File "redis/connection.py", line 182, in close
    self.purge()
  File "redis/connection.py", line 176, in purge
    self._buffer.seek(0)

send_packed_command encountered a socket.error (error(9, 'Bad file descriptor')). It tries to call self.disconnect() but gets a ValueError inside the close/purge of the SocketBuffer used by the PythonParser, so it never gets to raise ConnectionError. The relevant bit from Connection.send_packed_command is:

        except socket.error:
            e = sys.exc_info()[1]
            self.disconnect()
            if len(e.args) == 1:
                _errno, errmsg = 'UNKNOWN', e.args[0]
            else:
                _errno, errmsg = e.args
            raise ConnectionError("Error %s while writing to socket. %s." %
                                  (_errno, errmsg))

I think the SocketBuffer.close should catch and ignore this error or possibly just log it. If the SocketBuffer._buffer isn't there anymore while we try to remove it, so be it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions