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

cmd/go: "go version" fails if CWD is deleted #34499

Closed
dotaheor opened this issue Sep 24, 2019 · 7 comments
Closed

cmd/go: "go version" fails if CWD is deleted #34499

dotaheor opened this issue Sep 24, 2019 · 7 comments
Labels
FrozenDueToAge GoCommand cmd/go help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@dotaheor
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.13 linux/amd64

Does this issue reproduce with the latest release?

true

What did you do?

$ cd /tmp
$ mkdir aaa
$ cd aaa
$ go version
go version go1.13 linux/amd64
$ rmdir ../aaa
$ go version
2019/09/24 11:26:36 cannot determine current directory: getwd: no such file or directory
$ which go
sh: 0: getcwd() failed: No such file or directory
/home/myname/go-sdk/bin/go

What did you expect to see?

go version should be unrelated to CWD.

What did you see instead?

go version needs to confirm CWD.

@mvdan
Copy link
Member

mvdan commented Sep 24, 2019

How realistic is this scenario? I agree that technically this should work, but in practice cmd/go does quite a bit of work at init time, before the main function or the version command are run. This includes getting the current working directory.

I assume this helps keep the global simpler, as one can rely on base.Cwd to be valid. We could move the error check out of init and into each of the uses of Cwd, perhaps turning it into a function like base.Cwd() that would run os.Getwd the first time it's called instead of at init time.

I'm just not convinced that this is worth the effort. For example, do we want to add cmd/go tests where the current directory has been removed?

/cc @bcmills @jayconrod

@mvdan mvdan added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Sep 24, 2019
@bcmills bcmills added this to the Unplanned milestone Sep 24, 2019
@bcmills bcmills added the NeedsFix The path to resolution is known, but the work has not been done. label Sep 24, 2019
@bcmills
Copy link
Contributor

bcmills commented Sep 24, 2019

I think it would be fine to accept a fix for this, provided that the fix is not too invasive in practice, but I do not plan to fix it myself.

@gopherbot gopherbot removed the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Sep 24, 2019
@bcmills bcmills added the GoCommand cmd/go label Sep 24, 2019
@AndersonQ
Copy link
Contributor

I was trying to reproduce and investigate, but I cannot. It might be platform/shell specific

###What version of Go are you using (go version)?
$ go version
go version go1.13 darwin/amd64

What did you do?

$ cd /tmp
$ mkdir aaa
$ cd aaa
$ go version
go version go1.13 darwin/amd64
$ rmdir ../aaa
$ go version
go version go1.13 darwin/amd64

It works on both zsh and bash for me

@bcmills
Copy link
Contributor

bcmills commented Sep 25, 2019

@AndersonQ, note that the original report was on linux. The filesystem on darwin platforms tends to behave differently.

@hasitpbhatt
Copy link
Contributor

I think it would be fine to accept a fix for this, provided that the fix is not too invasive in practice, but I do not plan to fix it myself.

The question here is, do we really want to go for a global singleton route?
Because in principle, Cwd should not be initialized unless it is needed, but adding a singleton will open up lock(multi-threads?), singleton abuse and all sorts of other things.

@gopherbot
Copy link

Change https://golang.org/cl/268261 mentions this issue: cmd/go: fix the crash of the go version command when executed in a deleted directory

sauterp added a commit to sauterp/go that referenced this issue Nov 17, 2020
If the go command is executed on Linux in a deleted directory,
it fails. This behavior is reasonable for commands which depend on
the CWD, but it's unexpected for commands like `go version`.
This change delays initialization of a global CWD variable.

Fixed golang#34499

Change-Id: I7302fb84a3b7f5f149a123d277abd5b9b5bc95b2
sauterp added a commit to sauterp/go that referenced this issue Nov 19, 2020
If the go command is executed on Linux in a deleted directory,
it fails. This behavior is reasonable for commands which depend on
the CWD, but it's unexpected for commands like `go version`.
This change delays initialization of a global CWD variable.

Fixed golang#34499

Change-Id: I7302fb84a3b7f5f149a123d277abd5b9b5bc95b2
sauterp added a commit to sauterp/go that referenced this issue Nov 21, 2020
If the go command is executed on Linux in a deleted directory,
it fails. This behavior is reasonable for commands which depend on
the CWD, but it's unexpected for commands like `go version`.
This change delays initialization of a global CWD variable.

Fixed golang#34499

Change-Id: I7302fb84a3b7f5f149a123d277abd5b9b5bc95b2
sauterp added a commit to sauterp/go that referenced this issue Dec 1, 2020
If the go command is executed on Linux in a deleted directory,
it fails. This behavior is reasonable for commands which depend on
the CWD, but it's unexpected for commands like `go version`.
This change delays initialization of a global CWD variable.

Fixed golang#34499

Change-Id: I7302fb84a3b7f5f149a123d277abd5b9b5bc95b2
sauterp added a commit to sauterp/go that referenced this issue Dec 5, 2020
If the go command is executed on Linux in a deleted directory,
it fails. This behavior is reasonable for commands which depend on
the CWD, but it's unexpected for commands like `go version`.
This change delays initialization of a global CWD variable.

Fixed golang#34499

Change-Id: I7302fb84a3b7f5f149a123d277abd5b9b5bc95b2
@gopherbot
Copy link

Change https://golang.org/cl/317249 mentions this issue: cmd/go: skip TestExecInDeletedDir on aix and solaris-based platforms

gopherbot pushed a commit that referenced this issue May 5, 2021
They empirically do not seem to support deleting the current working
directory.

Updates #34499

Change-Id: I705cdf8b545fbb837d5b75d2904a7c2a89276fa5
Reviewed-on: https://go-review.googlesource.com/c/go/+/317249
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
@golang golang locked and limited conversation to collaborators May 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge GoCommand cmd/go help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

6 participants