backport b68098ebbaaa3bd816d24c1ed304425e838ee6b8 to stable6

cc @DeepDiver1975