Fix race condition when rehashing