Fix potential deadlocks in res_monitor