Skip to content

x/tools/cmd/goimports: escaping Go path resulting in 55 million syscalls #17916

@cstockton

Description

@cstockton

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

Go 1.7.3

What operating system and processor architecture are you using (go env)?

Linux / amd64

What did you do?

I am using Atom with go-plus, which runs goimports on file save. It's always taken a small delay of 500ms-1s to save files, something I've lived with because it's convenient. Today I symlinked a folder in the root of my Go path from my backup partition to access previous work temporarily.. after saving a file that needed a new import added atom locked up for 20-30 seconds, I waited and after this the notice delays were still 4-6 seconds each save.

I decided to see what the cause was and started with a top, noticed all 24 of my dual xeon processors maxed out with goimports. I run goimports -d client_test.go on the file I was working on and noticed the same delay. Then I ran strace -o out -f goimports -d client_test.go to see what work it was doing, this resulted in about 10 minutes and a 6gb strace file -rw-r--r-- 1 cstockton cstockton 6179399530 Nov 14 11:16 out. After inspecting it I noticed it was primarily stat and open calls. I grepped out all of my $GOPATH and noticed it was entering into other directories on my machines main storage.

I believe the reason this was happening is due to a unrelated python project located at $GOPATH(/one)/local/py/ which had a symlink to the parent dir of my $GOPATH (/one). This is the mount points root file system which is bind mounted with mount -t none -o bind /storage/one /one though I don't think this detail matters, it could. The /storage dir is where I keep all my files and goimports ends up visiting every file, music directory, etc. I haven't noticed this because I have 6 ssd's in raid 10 and 256gb of ram, so the first pass is slow but my OS caching makes work reasonable after that despite this heavy I/O.

When I symlinked to my /backup partition to reference another project the same thing happened, but to 8 physical spinning disks with many times the data. I'm not sure how it ended up in the root of my backup partition.

File:
-rw-r--r-- 1 cstockton cstockton 6179399530 Nov 14 11:16 out

Grepping out signal noise, the total syscalls was 55million:
cat out |grep -v " <... " | wc -l 55861212

What did you expect to see?

No escaping my GOPATH under any circumstance, but perhaps it is documented that symlinks outside GOPATH are permitted and this could be considered my "fault" and not a bug. However if memory serves me properly in the past symlinks did not work well with much of Go's tooling and build tools so I've never relied on them, so didn't think anything of it.

What did you see instead?

Escaping GOPATH.

Sorry for the noise if this is not a bug or the appropriate place to post this, I visited the tools repo but it only has contribution guidelines, nothing for bugs or issues.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions