Partial forwardport of 3cc5cc79 from stable/1.8.x as the issue was already fixed in master in a7bc00e1