backport some discovery fixes from master
Fix possible block during discovery