Close socket when factory fails.

The socket is not exposed to the outside anyway, so it should be closed.