Skip to content

os: don't waste extra threads for opening files #32618

@Al2Klimov

Description

@Al2Klimov

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

$ go version
go version go1.12.6 darwin/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
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/aklimov/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/aklimov/Git/golang"
GOPROXY=""
GORACE=""
GOROOT="/Users/aklimov/Git/brew/Cellar/go/1.12.6/libexec"
GOTMPDIR=""
GOTOOLDIR="/Users/aklimov/Git/brew/Cellar/go/1.12.6/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/3h/0nn80rp973b08bd0r56g5pd80000gn/T/go-build873614728=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

  1. I've built the program shown below,
  2. ran mkfifo pipe and
  3. ran GOMAXPROCS=1 lldb theprogramshownbelow.
package main

import (
	"fmt"
	"os"
	"runtime"
	"time"
)

func main() {
	for i := runtime.NumCPU() * 2; i > 0; i-- {
		go openPipe()
	}

	for {
		time.Sleep(time.Second)
	}
}

func openPipe() {
	p, errOpen := os.Open("./pipe")
	fmt.Printf("os.Open(\"./pipe\"): %#v\n", errOpen)
	p.Close()

	for {
		time.Sleep(time.Second)
	}
}

What did you expect to see?

Not much more threads than one.

What did you see instead?

11 threads including a lot of hanging in the open(2) syscall.

Metadata

Metadata

Assignees

No one assigned

    Labels

    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