[v12.x] backport 27227
This is a semver-patch backport of #27227.
This is not going to resolve the conflict with #27522 but it will still help in potential other future changes.
Update: I added the manual backport of #27522 as well.
Checklist
-
make -j4 test
(UNIX), orvcbuild test
(Windows) passes -
tests and/or benchmarks are included -
documentation is changed or added -
commit message follows commit guidelines