Add lock to fake handler to avoid races.

Hopefully closes #1814, although I couldn't reproduce it.