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: hangs with 100% CPU on import of absolute path #27474

Closed
bmeh opened this issue Sep 3, 2018 · 5 comments
Closed

cmd/go: hangs with 100% CPU on import of absolute path #27474

bmeh opened this issue Sep 3, 2018 · 5 comments

Comments

@bmeh
Copy link

bmeh commented Sep 3, 2018

./logger/vendor/*
./logger/go.mod
./logger/logger.go
./logger/go.sum
./main.go
./main

In main.go:

import "./logger"

It works with go build main.go, but does not work with go build -mod vendor main.go because it says:

build flag -mod=vendor only valid when using modules

Of course it tells me this because go.mod doesn't exist for main.go, so upon creating it through go mod init main, it creates the file with only module main and no dependencies. This doesn't help though, because then it tells me this:

$ go build -mod vendor main.go
build main: cannot find module for path _/home/bmeh/foo/logger

even though logger/go.mod exists, and is correct.

The thing is, go build main.go works, but go build -mod vendor main.go doesn't, so my question is, how do I make it work with go build -mod vendor main.go? Ideally main.go's dependency on ./logger should be in main's go.mod, but it might not support "local" modules for all I know. I'm not exactly sure what's the proper way to use internal, library packages that are used only by this project. The reason I need it for is modularization. Some projects import github.com/user/project/foo/utils, github.com/user/project/foo/logger and so on, but using import "./logger" seems to do fine for me, apart from not working well with vendoring. I also have read something about naming internal packages internal, but I have not came across any usable, working examples (to be honest, I wasn't trying to find any hard enough :P). Any input and suggestions from "experts" would be greatly appreciated.

Worth noting that go build alone will give me back this error:

go build _/home/bmeh/foo: build output "logger" already exists and is a directory

Not sure if this behavior is intended or not either.

Thank you for your help in advance!

Edit:

Changing the import path to the absolute path ("./logger" -> "/home/bmeh/foo/logger") makes go hung up and eat 100% CPU when using go build -mod vendor main.go. No longer gives the aforementioned errors. I believe this is a bug. Please do correct me if I am wrong.

Passing -x:

WORK=/tmp/go-build518771439

The directory is empty.

Partial strace:

futex(0xd618c0, FUTEX_WAIT_PRIVATE, 0, {tv_sec=0, tv_nsec=100000}) = -1 EAGAIN (Resource temporarily unavailable)
futex(0xc000046840, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0xd617f0, FUTEX_WAKE_PRIVATE, 1)  = 1
futex(0xd627c0, FUTEX_WAIT_PRIVATE, 0, NULL

and it just hangs indefinitely.

@myitcv
Copy link
Member

myitcv commented Sep 3, 2018

Hi @bmeh ,

This appears to be a question rather than a Go bug. We do not use the issue tracker for general discussions or questions like these. The Github bug tracker is only used for tracking bugs and proposals going through the Proposal Process.

You might want to take a look at Questions wiki page; it has a list of good places for asking questions.

Therefore closing this issue.

@myitcv myitcv closed this as completed Sep 3, 2018
@bmeh
Copy link
Author

bmeh commented Sep 6, 2018

@myitcv Please take a look at the original post, I edited it a couple of days ago. I don't think it's supposed to hang indefinitely and eat 100% CPU seemingly doing nothing (see the last lines of strace, it remains the same for 5 minutes, I ^C'd afterwards), as it shows only what I mentioned, and does nothing to that directory, it remains empty even after 5 minutes. If you want I could run it for an hour and give you the full strace output, or perhaps you could reproduce this behavior and see for yourself whether it's intended or not. Same environment variables and version (go version go1.11 linux/amd64) as in my previous issue.

Feel free to change the title of this issue accordingly if it indeed is a bug.

@myitcv
Copy link
Member

myitcv commented Sep 7, 2018

@bmeh as you point out, relative import paths will not work. They might work with go run <files> but with GOPATH/modules mode they will not work at all.

Using an absolute path for an import path is also undefined (although I agree it should fail more gracefully than simply hanging). I will retitle the issue for this bug.

From the directory layout in your original description it looks like you want a replace directive. Please see go help mod edit or https://github.com/golang/go/wiki/Modules#when-should-i-use-the-replace-directive

@myitcv myitcv reopened this Sep 7, 2018
@myitcv myitcv changed the title How do I use modules (go build -mod vendor) with local packages? (help wanted) cmd/go: hangs with 100% CPU on import of absolute path Sep 7, 2018
@myitcv
Copy link
Member

myitcv commented Sep 7, 2018

On reflection @bmeh it's going to be a bit of work to re-edit your description in this issue, so I'll close this issue. Please can you open a new issue, completing the issue template, with details of the hang? Thanks

@myitcv myitcv closed this as completed Sep 7, 2018
@bmeh
Copy link
Author

bmeh commented Sep 8, 2018

@myitcv Opened a new issue a couple of hours ago: #27558

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants