(#477) - Fix race condition in db.changes

This PR probably fixes a race condition mentioned in #477. "Probably", because I cannot reproduce this bug on my machine. @neojski, could you check if it works for you?