[backport] Fix possible race condition on register using select for update.