Repository navigation
syscall: be more helpful with Windows DLLs fail to load due to missing environment variables #25210
Description
Activity
- addedNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
on May 2, 2018 Actually, I'm hitting this reliably with Windows 10, Go 1.10.1, and Perkeep git rev https://camlistore.googlesource.com/camlistore/+/b9ab98d60de97f2e78913aecb587dd6013189eaa
Notably, that
calculateMultipartOverheadruns at init time.Is one not allowed to use crypto/rand on Windows at init time?
/cc @mpl
Ah, we had a child process that was being run in an integration test with an incomplete environment.
I discovered it because after I worked around this issue (by calculating the
calculateMultipartOverheadlazily on first use with async.Onceinstead of atinittime), then my test started failing with different but related errors about network initialization.Could we repurpose this bug about making such Windows debugging adventures easier?
Can we log or return a better error somewhere when a DLL fails to load and we additionally have missing environment variables?
(sorry for talking to myself)
- changed the title
[-]crypto/rand: CryptAcquireContext: Provider DLL failed to initialize correctly[/-][+]syscall: be more helpful with Windows DLLs fail to load due to missing environment variables[/+]on May 2, 2018 Can we log or return a better error somewhere when a DLL fails to load and we additionally have missing environment variables?
I suppose the problem here is that syscall.CryptAcquireContext requires some environment variable set. We could find out what it needs and then check syscall.CryptAcquireContext error number, and if error number matches and that particular environment variable set, we could return different error message. I am just not sure, if that would be OK to change error message returned, because other people could be expecting that error.
But really - passing nearly empty environment to you child process on Windows is looking for trouble. I wish our API would stop us doing that.
Alex
But really - passing nearly empty environment to you child process on Windows is looking for trouble. I wish our API would stop us doing that.
Yeah, that's another possibility: on Windows we could force certain environment variables to be inherited in os/exec. Perhaps if they're not mentioned at all, we auto-add them, but if the user really, really wants to run the child process with an empty environment key, they can set it to the empty string?
Reacted by Jannis Andrija Schnitzer- added a commit that references this issue
on May 3, 2018 Perhaps it has been discussed before, but why does
os.Environ()returns[]string? Shouldn't it returnmap[string]string?map[string]stringwould work on Unix. Unfortunately Windows does not distinguish betweenPATHandpathenvironment variables, somap[string]stringis not good for Windows.Alex
@alexbrainman, let's leave such discussion to newly-opened #25252
I don't think we should do anything in syscall but I think it would be appropriate for os/exec to take care of this and say that unless SYSTEMROOT (or SystemRoot, systemroot, etc) is specified explicitly on Windows, it's copied in implicitly.
Change https://golang.org/cl/124858 mentions this issue:
cmd/go: preserve %SYSTEMROOT% in TestScript on Windows- added a commit that references this issue
on Jul 19, 2018 I think it would be appropriate for os/exec to take care of this and say that unless SYSTEMROOT .... is specified explicitly on Windows, it's copied in implicitly.
Too much magic for me. If I don't include SYSTEMROOT in my environment, I expect os/exec not to put it there.
Also how do you know that SYSTEMROOT is what is missing to fix your failure? What about other environment variables? Different libs / packages installed on my computer adds different environment variables. How are you going to support these libs / packages?
I think it is much simpler, when creating child process, just copy parent environment and add / remove / modify whatever environment variables you like.
Alex
os/exec is a high-level helper package. It's quite common for people to forget to copy the parent environment, so I think it's fine to auto-add critical environment variables that aren't mentioned explicitly.
Also how do you know that SYSTEMROOT is what is missing to fix your failure? What about other environment variables? Different libs / packages installed on my computer adds different environment variables. How are you going to support these libs / packages?
So far it's been implicated several times now. I think fixing the common ones is enough. We don't have to do all of them.
I think it is much simpler, when creating child process, just copy parent environment and add / remove / modify whatever environment variables you like.
In retrospect that should've been the API from the beginning (a list of modifications, rather than the new environment completely), but that's not where we're at.
Change https://golang.org/cl/174318 mentions this issue:
os/exec: always set SYSTEMROOT on Windows if not listed in Cmd.Env- locked and limited conversation to collaborators
on Apr 28, 2020
I've been trying to get the Perkeep tests passing on Windows and just hit this flake with Go 1.10 that I've never seen before or found other reports of:
Any ideas?
/cc @alexbrainman