Apply patch for https://github.com/rails/rails/issues/917 to 2-3-stable

We are now getting bitten by this bug in our production system (2.3.15).  This patch is identical to the solution put forth by Brad Gessler in the linked issue.