Avoid deadlock during initial scan (fixes #389)