Fixed CLOSE_WAIT socket problem by introducing 5 second read deadline and properly detecting timeout errors.