fix multiple callbacks when socket errors occur

Realized there might be a case where the socket errors on a write,
and then there are multiple write calls. Each write will emit an
error, causing multiple callbacks for things like publish