Fix race condition in document indexing

Signed-off-by: Andreas Knab <knabar@gmail.com>