Backport of #7347 to stable6

Backport of #7347 to stable6

\cc @DeepDiver1975