Backport of #15764 and #15902 to 4-1-stable

Backport of #15764 and #15902 to _4-1-stable_ branch. That was a Ruby breaking bug so It should be backported.