Fixes a bug when disconnecting a session