Fix some more race conditions

Another `-race` load testing.
I'm not very sure about changes to `server/buildfile.go`, but it seems working good.
ping @vieux @unclejack @crosbymichael
Should the lock be kept for the Sort?