Make registration cancellation thread-safe

Lock the write lock before removing the registration and setting
the refreshRequest flag.

Fixes #46