Fix race conditions

I've built docker with race flag and found some race condition. After fixes, with 15 minutes load of `./docker-stress -c 20 -t 1`  I didn't saw any races.