Fix a race in the amgr found by the race detector.