There must be some race condition, but adding debugging logging makes this work.