fix error handling problem when closing the server to early