backport 4.7 changes to socket timeout and short read condition handling