improve error handling: when closing socket/acceptor, the callback registered will still be called, so we should check if the socket/acceptor has been closed in the callback