Fix potential deadlock spotted by Richard Vida.