Repository: redis/redis-py
File: redis/cluster.py (Python)

Code before:
                        redis_node.connection_pool,
                        connection,
                    )
                nodes[node_name].append(c)
                break

        # send the commands in sequence.
        # we  write to all the open sockets for each node first,
        # before reading anything
        # this allows us to flush all the requests out across the
        # network essentially in parallel
        # so that we can read them all in parallel as they come back.
        # we dont' multiplex on the sockets as they come available,
        # but that shouldn't make too much difference.
        node_commands = nodes.values()
        for n in node_commands:
            n.write()

        for n in node_commands:
            n.read()

        # release all of the redis connections we allocated earlier
        # back into the connection pool.
        # we used to do this step as part of a try/finally block,
        # but it is really dangerous to
        # release connections back into the pool if for some
        # reason the socket has data still left in it
        # from a previous operation. The write and
        # read operations already have try/catch around them for
        # all known types of errors including connection
        # and socket level errors.
        # So if we hit an exception, something really bad
        # happened and putting any oF
        # these connections back into the pool is a very bad idea.
        # the socket might have unread buffer still sitting in it,
        # and then the next time we read from it we pass the
        # buffered result back from a previous command and
        # every single request after to that connection will always get
        # a mismatched result.
        for n in nodes.values():
            n.connection_pool.release(n.connection)

        # if the response isn't an exception it is a
        # valid response from the node
        # we're all done with that command, YAY!
        # if we have more commands to attempt, we've run into problems.
        # collect all the commands we are allowed to retry.
        # (MOVED, ASK, or connection errors or timeout errors)
        attempt = sorted(
            (
                c

Review comment (suggestion):
This comment seems out-of-date — isn't it explaining why _not_ to do exactly what this change is doing?

It should probably be update to explain why this _is_ safe, not why it _isn't_. 😅 

Code after:
                        redis_node.connection_pool,
                        connection,
                    )
                nodes[node_name].append(c)
                break

        # send the commands in sequence.
        # we  write to all the open sockets for each node first,
        # before reading anything
        # this allows us to flush all the requests out across the
        # network essentially in parallel
        # so that we can read them all in parallel as they come back.
        # we dont' multiplex on the sockets as they come available,
        # but that shouldn't make too much difference.
        node_commands = nodes.values()
        try:
            node_commands = nodes.values()
            for n in node_commands:
                n.write()

            for n in node_commands:
                n.read()
        finally:
            # release all of the redis connections we allocated earlier
            # back into the connection pool.
            # we used to do this step as part of a try/finally block,
            # but it is really dangerous to
            # release connections back into the pool if for some
            # reason the socket has data still left in it
            # from a previous operation. The write and
            # read operations already have try/catch around them for
            # all known types of errors including connection
            # and socket level errors.
            # So if we hit an exception, something really bad
            # happened and putting any oF
            # these connections back into the pool is a very bad idea.
            # the socket might have unread buffer still sitting in it,
            # and then the next time we read from it we pass the
            # buffered result back from a previous command and
            # every single request after to that connection will always get
            # a mismatched result.
            for n in nodes.values():
                n.connection_pool.release(n.connection)

        # if the response isn't an exception it is a
        # valid response from the node
        # we're all done with that command, YAY!
        # if we have more commands to attempt, we've run into problems.
        # collect all the commands we are allowed to retry.
        # (MOVED, ASK, or connection errors or timeout errors)
        attempt = sorted(