Fix race between dispatchers.run and toDisk

Signed-off-by: Alexandr Morozov <lk4d4math@gmail.com>
Merge pull request #7883 from LK4D4/fix_build_race

Fix race between dispatchers.run and toDisk