calling recv_done() with ISC_R_CANCELED prevents dig from cleaning up fully from the query, because when that result code is used it means some resources are already gone. changing the result to ISC_R_UNEXPECTED prevents the hang.