Yep, I can confirm that I've run into exactly the same problem. What I did end up doing was to put a sync ; sleep 1 sequence between the 'fdisk' and the 'mkfs' command (as a 'sync' on it's own did not seem to be sufficient).
That might be a bit of a kludge as there is no proper check and there might be situations where one seconds could be not enough. But I really did not want to spend too much time in finding a proper solution, when a simple work-around appeared to do as well (at least in my case).