Skip to content

os/exec: go fmt fails inside docker container #34318

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

Closed
zrma opened this issue Sep 16, 2019 · 5 comments
Closed

os/exec: go fmt fails inside docker container #34318

zrma opened this issue Sep 16, 2019 · 5 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@zrma
Copy link

zrma commented Sep 16, 2019

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?

yes

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build831486306=/tmp/go-build -gno-record-gcc-switches"
r

What did you do?

run this code in docker image golang:1.13.0

binPath := runtime.GOROOT()
binPath = filepath.Join(binPath, "bin", "go")

srcPath := os.Getenv("GOPATH")
srcPath = filepath.Join(srcPath, "src", "app", "cmd", "filename.go")

cmd := exec.Command(binPath, "fmt", srcPath)
if err := cmd.Start(); err != nil {
    log.Println(err)
}
if err := cmd.Wait(); err != nil {
    // Error has occurred.
    log.Println(err)
}

What did you expect to see?

It works well.
I apply go fmt to "app/cmd/filename.go" file exactly.

What did you see instead?

In windows, golang 1.13.0 It works.
In ubuntu, WSL golang 1.13.0 It works.
In docker image golang:1.12.9, It works.
In docker image golang:1.13.0 It failed.

 <*exec.ExitError | 0xc00000e820>: {
          ProcessState: {
              pid: 1388,
              status: 256,
              rusage: {
                  Utime: {Sec: 0, Usec: 350000},
                  Stime: {Sec: 0, Usec: 240000},
                  Maxrss: 18304,
                  Ixrss: 0,
                  Idrss: 0,
                  Isrss: 0,
                  Minflt: 9364,
                  Majflt: 0,
                  Nswap: 0,
                  Inblock: 352,
                  Oublock: 7368,
                  Msgsnd: 0,
                  Msgrcv: 0,
                  Nsignals: 0,
                  Nvcsw: 15901,
                  Nivcsw: 1747,
              },
          },
          Stderr: nil,
      }
      exit status 1

If I run command in bash shell directly from cmd.String() output
(like /usr/local/go/bin/go fmt /go/src/app/cmd/filename.go) at golang:1.13.0 docker image,
it works well.

Thank you.

@smasher164 smasher164 changed the title os.exec: exec.Command run failed "go xxx" command which does file I/O in 1.13.0 os/exec: go fmt fails inside docker container Sep 17, 2019
@smasher164
Copy link
Member

I am unable to reproduce this behavior. Here are the steps I followed. Is there anything different about your execution?

$ docker run -it golang:1.13.0
/go# mkdir -p src/app/cmd
/go# cat > src/app/cmd/filename.go
package main

import (
"log"
"os/exec"
"path/filepath"
"runtime"
"os"
)

func main() {
binPath := runtime.GOROOT()
binPath = filepath.Join(binPath, "bin", "go")

srcPath := os.Getenv("GOPATH")
srcPath = filepath.Join(srcPath, "src", "app", "cmd", "filename.go")

cmd := exec.Command(binPath, "fmt", srcPath)
if err := cmd.Start(); err != nil {
    log.Println(err)
}
if err := cmd.Wait(); err != nil {
log.Println(err)
}
}
^C
/go# go run src/app/cmd/filename.go
/go# cat src/app/cmd/filename.go
package main

import (
    "log"
    "os"
    "os/exec"
    "path/filepath"
    "runtime"
)

func main() {
    binPath := runtime.GOROOT()
    binPath = filepath.Join(binPath, "bin", "go")

    srcPath := os.Getenv("GOPATH")
    srcPath = filepath.Join(srcPath, "src", "app", "cmd", "filename.go")

    cmd := exec.Command(binPath, "fmt", srcPath)
    if err := cmd.Start(); err != nil {
        log.Println(err)
    }
    if err := cmd.Wait(); err != nil {
        log.Println(err)
    }
}

@smasher164 smasher164 added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Sep 17, 2019
@zrma
Copy link
Author

zrma commented Sep 17, 2019

@smasher164

Thank you for your interest in this issue.
There was a lack of basic information.

I ran it the same way as you and it worked fine.
When I ran the docker image with the host volume mounted, a failure occurred, like this.
docker run -it --rm -v d:\gopath\src\app:/go/src/app golang:1.13.0

I use docker desktop community version 2.1.0.3(38240)
OS : windows 10 version 1709(OS build 16299.1087)

It failed with ci runner docker in gitlab running as a self-host, too.
gitlab ci logs are like this.

Running with gitlab-runner 11.5.0 (3afdaba6)
on Shared.Linux.Docker.01 fc8c0bfa
Using Docker executor with image registry-gitlab-host/group/project/golang:1.13.0 ...
Pulling docker image registry-gitlab-host/group/project/golang:1.13.0 ...
Using docker image sha256:ae999aee95607f18ff924f57cc334fe2089903398ae9a0c9480a38d8b3c7fe5f for registry-gitlab-host/group/project/golang:1.13.0 ...
Running on runner-fc8c0bfa-project-1369-concurrent-0 via gitce-runl01.nxdmz.net...

Under the same conditions(on docker images with volume mounted / gitlab-ci worker on docker),
until golang version 1.12.9 worked fine.

Thank you.

@smasher164 smasher164 added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Sep 18, 2019
@smasher164
Copy link
Member

I'm going to try reproducing this on a windows server installation. Will report back with details.

@zrma
Copy link
Author

zrma commented Sep 18, 2019

@smasher164

Thank you so much.
I found the reason.

It's my mistake, so sorry.
Your example works fine with or without the docker volume mounted also.

In my original case, I was vendoring and storing a module in a private repository,
but go modules tried to access it, even if I set go env GOPRIVATE, and it failed.
So the child process was dying.

Thank you.

@zrma zrma closed this as completed Sep 18, 2019
@zrma
Copy link
Author

zrma commented Jan 1, 2020

I wrote some notes with additional informations.

if it’s case like that(using vendor option with a private repository),
I should run go commands with -mod=vendor options.

ex) go build -mod=vendor [target]

Thanks.

@golang golang locked and limited conversation to collaborators Dec 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants