Add optional debugging to investigate [issue 8631](https://github.com/matrix-org/synapse/issues/8631).