db: fixed race problems.