Git Product home page Git Product logo

Comments (1)

KazWolfe avatar KazWolfe commented on August 18, 2024

So, finally came back to this and think I figured out the problem. When binding to http://localhost as a URL prefix, EndPointManager will only grab the first resolution from Dns.GetHostAddresses(). On most systems, this will be the IPv6 loopback address of ::1. The actual resolution for 127.0.0.1 goes completely ignored. The EmbedIO listener will then dutifully set up its listener on ::1, as we expect.

Because, however, we are also registering to http://127.0.0.1, EmbedIO binds to both the IPv4 and IPv6 interfaces. When running curl --ipv4 http://localhost:45454/, we connect to the IPv4-only EndPointListener which is not aware of the localhost prefix:

image

As a result, the server steps through SearchListener, fails to find an appropriate match, and BindContext returns false, killing the connection:

image

(Of note, while exploring this, I came across issue #165 which had a similar comment - binding to 0.0.0.0 actually creates something that listens on all interfaces, but because the EndPointListener is not aware of 0.0.0.0 being "special", it also gives up. This is doubly made interesting by the fact that EndPointManager.cs#L96 actually has something in place for this edge case, allowing it to bind to [::] instead, but I'm on a tangent so I'll get back to the issue at hand.)

As an experiment, I wrote a (very quick and dirty) patch that changed the behavior of GetEpListener to instead return a list of eligible listeners (assuming more than one is returned by the aforementioned DNS query). This, to my surprise, actually seems to work:

image

The localhost prefix is added to both the IPv4 and IPv6 listeners, and cURL can connect to either one and receive the expected response. In addition, the actual IP addresses also defined also can connect and get routed appropriately, bringing everything back to what I would have expected. I'm more than happy to formally submit this patch as a PR, but I'm unsure what else would be needed before then (and what other things are lurking in EndPointListener that should be looked at).

(Edit: The above patch diverges from Mono's behavior, which I suspect is not a desired change. Would it make sense to open this issue with the Mono team directly? As far as I can tell from Mono's code, they'd have the same problem - setting prefixes to 127.0.0.1 and [::1] would work, but connects with Host: localhost would be rejected. All this to say EmbedIO v4 can't come soon enough!)

As for why all this came up in the first place: browsers are problematic. Despite the fact that Windows is usually pretty consistent (ha) about returning DNS records for localhost in the same order, browsers will sometimes decide that they want to swap things around or prefer IPv4 to IPv6 at times. This causes the browser to resolve localhost to 127.0.0.1 and hit the EndPointListener with no knowledge that it should be responding to localhost, because all it knows is IPv6.

from embedio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.