Backport fix for ENG-5769 to the 4.0.1.x branch.  

Applied patch generated with:
git diff -p 0382148...eb7e936