write_or_die: handle EPIPE in async threads