In theory it would be better to detect this bug in advance, but this approach is much simpler, and therefore safer to backport. This closes tor issue 28973.