Backported two commits which may fix #8419

I could not test this fix because rubygems is down at the moment and I
want to got to bed now... :)