core: fix race condition where resource is deleted while also being pivoted.

(cherry picked from commit 6df5a8809dee4df2555611255a76c9382c8c1a0c)