add protection around db access since it may be attempted from 2 threads at once