Bugfix for when a connection is closed unexpectedly

If a connection was made and then the browser was refreshed (to simulate
a sudden connection disruption) the server would crash which is fixed
now.