Fix timeout so that it gets cancelled when the connection is closed