move socket sending and error emitting to nextTick to allow error handler setup