fix raf race condition