Fix NPE crash by using spin wait