Fix race condition which could lead to a chunk not being saved correctly

Signed-off-by: Ross Allan <rallanpcl@gmail.com>