Fix bug in socket timeout per PR #161 by maciejkula, add test