The bug appears when a session command that is executed on the master fails. The logic in the code doesn't take this case into consideration when it processes failed connections.