Skip to content
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

localhost does not resolve #135

Open
alex-shapiro opened this issue Jun 26, 2017 · 5 comments
Open

localhost does not resolve #135

alex-shapiro opened this issue Jun 26, 2017 · 5 comments

Comments

@alex-shapiro
Copy link

alex-shapiro commented Jun 26, 2017

I tried to open an async connection to a server running locally at ws://localhost:4000 and received the following error:

IoError(Error { repr: Os { code: 61, message: "Connection refused" } })

However, the following work:

  • opening an async websocket connection to ws://127.0.0.1:4000. So my code connects once DNS is resolved.
  • opening an async websocket connection to ws://echo.websocket.org. So websocket DNS resolution does work in some cases.
  • opening a synchronous websocket connection to ws://localhost:4000. So local DNS resolution works but only for synchronous connections.
  • opening an async HTTP connection to http://localhost:4000 with Hyper 0.11. Does Hyper 0.11 use a different Tokio primitive to resolve DNS?

I'm not exactly sure what's going on. It's not a big deal - I'm manually resolving localhost to 127.0.0.1 - but I'm kind of curious.

@illegalprime
Copy link
Collaborator

Good catch! It's probably this code:
https://github.com/cyderize/rust-websocket/blob/master/src/client/builder.rs#L800

Instead of calling next() you should create a TcpStream with that iterator and then turn it into an async one with the async TcpStream's API.

@alex-shapiro
Copy link
Author

That means the DNS lookup would be done synchronously, right?

@illegalprime
Copy link
Collaborator

hmm... that's a good point. I wonder how hyper 0.11 is doing it

@alex-shapiro
Copy link
Author

Looks like Hyper wraps a synchronous DNS call inside a future: https://github.com/hyperium/hyper/blob/master/src/client/dns.rs#L52.

@illegalprime
Copy link
Collaborator

We can try looping over the ToSocketAddr in the future (make one async DNS call, if that fails try again). This would get a really complicated type though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants