Call onClose after socket is closed

Call onClose from socket connection only after socket is closed