dns lookups: protect against cancellation and fix incorrect error codes