Backport 4c867952bfc2debebb265266ed524323114aab7a on 1.7.x, close #213