only flush if writeBuffer is length 0

in onClose, cleanup writeBuffer, callbackBuffer