-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
net: DNS doesn't work on Windows if environment is empty? #20473
Comments
@sajayantony |
You're replacing the entire environment of the child process with exactly 1 environment variable pair, removing all the standard Windows environment variables. Windows things are probably not happy if they lack their entire standard environment. You should use: programCmd.Env = append(programCmd.Env, fmt.Sprintf("%s=%s", "SOMETHING", pwd)) I bet that fixes it. I don't think we need to guarantee that Go programs work flawlessly in an empty environment. @alexbrainman, thoughts? |
@bradfitz |
Please post a complete but minimal self-contained repro. |
http.zip |
programCmd.Env is set to nil at the start, so appending 1 string to it, makes your environment have 1 environment variable - and that (as @bradfitz suggested) is not acceptable under Windows - some Windows APIs use these environment variables that you delete. Try this instead:
Alex |
Oh, whoops, thanks @alexbrainman. That's what I meant to write above but I was spacing out. Closing this since it looks like program error and/or something not fixable on Windows anyway. Comment if you disagree. |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?1.8.1
What operating system and processor architecture are you using (
go env
)?set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=D:\gopath181
set GORACE=
set GOROOT=D:\go181
set GOTOOLDIR=D:\go181\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\shhsu\AppData\Local\Temp\go-build529806931=/tmp/go-build -gno-record-gcc-switches
set CXX=g++
set CGO_ENABLED=1
set PKG_CONFIG=pkg-config
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
What did you do?
I created a go program that makes http requests. I want to be able to call that program from another go program. When calling the callee, the caller wants to be able to set an environment variable to modify its behavior
Example callee:
Example caller:
What did you expect to see?
http requests are successfully made
What did you see instead?
If I call
caller noEnv
everything is fine, the http request was successfully made with 200 status codeIf I call
caller
, the caller would pass the environmental variableSOMETHING={pwd}
, causing the following error on the calleeError reaching www.google.com, error: Get http://www.google.com: dial tcp: lookup www.google.com: getaddrinfow: A non-recoverable error occurred during a database lookup.
Example project on VSCode
The text was updated successfully, but these errors were encountered: