-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
proposal: net/http/httptest: listen on IPv6/IPv4-agnostic loopback address #56998
Comments
See also #31054 (comment) |
That's a good point. I've inquired about this internally and it appears there are a number of tests which don't do this. Now I need to figure out whether there are situations where not using URL is legitimate or at least hard to avoid. |
How are these tests finding an address to connect to? Can you give an example of how this would be used? I don't think listening on :0 by default works; you don't want your httptest server to be exposed to the external network. |
I've pointed the engineer handling this problem to this issue to engage. |
@neild responsible engineer here, I see a very common pattern as follows: client retrieves port and then try to connect “localhost:retrieved_port". this is rather common when server & client are separate executables and the client would simple have an arg —port= and assume/default hostname to be “localhost” |
It's more work to just get a port out of That said, I don't see anything fundamentally wrong with |
just a second thought, is it possible to add 2 new funcs to this library, namely, NewServerV6() & NewTLSServerV6() that explicitly try [::1] and just panic if failed? |
It seems very strange to me to not have |
Related:
Currently (1.20-dev), net/http/httptest listens preferentially on
127:0:0:1:0
, and falls back to[::1]:0
[1]. At work, our (modified) Linux kernel/system is planned to start behaving like this:net.Listen("tcp", "127.0.0.1:0")
succeeds (imagine it picked port 9999).net.Dial("tcp", "localhost:9999")
resolves to[::1]:9999
.This causes tests to fail, as
httptest.NewServer
only registers on IPv4 in this case. Given that httptest is much more limited in scope than thenet.Listener
(#9334), it may be feasible to change httptest behaviour to listen on:0
so that both IPv4 and IPv6 are listened on.The current behaviour in package net/http/httptest stems from f88abda (2011), it was copied as-is from the erstwhile fs_test aa9c213. I couldn't really find a reasoning for why we explicitly listen on 127.0.0.1, so I thought I'd propose this and see what I missed.
[1]:
go/src/net/http/httptest/server.go
Lines 60 to 75 in 7847260
The text was updated successfully, but these errors were encountered: