-
Notifications
You must be signed in to change notification settings - Fork 476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow specifying connection timeout in socket options #118
Conversation
I like this idea @rexxars but the timeout should be the default and not 0 if a timeout option is not specified. So i'd wrap that in an if clause instead. |
I agree there should be a default timeout - however, the default as of now is no timeout. Introducing a default timeout might be considered to be a breaking change, so I'd want to OK that with the maintainer first. Like I said, the default is 0, meaning no timeout. I could use an if clause, but in theory it should do pretty much the exact same as it does now. |
@rexxars yea thats totally my fault. I was assuming HTTP here which does have a default timeout. My apologies, this does look good. |
Supplying |
I didn't bother doing it since the socket was created in place, but optimizing for change makes sense. Latest commit checks if the timeout specified in options is actually set before assigning the timeout handler. |
Yup, looks good! |
Seems that this does not affect the timeout value for |
That .. is a good point @zweifisch. Casting my mind back, I think perhaps it was only intended to cover a failure to complete the handshake. But failing to establish a connection seems like something it could also cover with the minor modification you imply. What do you think, @rexxars? |
I agree, this looks like an oversight. I think this fixed a specific problem I had, but moving it outside the onConnect method should cover both connection and handshake timeouts. |
Since
connect()
does not return the socket instance, there is currently no easy way to set the connection timeout. This PR adds atimeout
option to the socket options passed toconnect()
, and automatically sets it on the socket when connecting. If a timeout is reached, it will trigger the connect callback with an error.This should solve #88 .