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

net/http: In the infinite loop, refused all requests. #17157

Closed
tonyboxes opened this issue Sep 19, 2016 · 1 comment

Comments

Projects
None yet
3 participants
@tonyboxes
Copy link

commented Sep 19, 2016

Please answer these questions before submitting your issue. Thanks!

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

go 1.6.2 mac/amd64

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/data/apps/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GO15VENDOREXPERIMENT="1"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"

What did you do?

package main

import (
    "net/http"
    "strconv"
    "fmt"
)

func main() {
    http.HandleFunc("/", httpHandler)
    http.ListenAndServe(":8001", nil)
}

func httpHandler(w http.ResponseWriter, r *http.Request) {
    b, _ := strconv.ParseBool(r.URL.Query().Get("loop"))
    if b {
        loop()
    }
    fmt.Fprintf(w, "ok")
}

func loop() {
    i := 0
    for {
        if i == 10000 {
            i = 0
        }
        i++
    }
}

1. curl http://127.0.0.1:8001/?loop=true
2. curl http://127.0.0.1:8001/?loop=false

When the loop to the CPU processing and about 8 times the request, refused to all the HTTP request.

What did you expect to see?

export GODEBUG=schedtrace=1000

SCHED 1010ms: gomaxprocs=8 idleprocs=8 threads=6 spinningthreads=0 idlethreads=3 runqueue=0 [0 0 0 0 0 0 0 0]
SCHED 2016ms: gomaxprocs=8 idleprocs=8 threads=6 spinningthreads=0 idlethreads=3 runqueue=0 [0 0 0 0 0 0 0 0]
SCHED 3019ms: gomaxprocs=8 idleprocs=8 threads=6 spinningthreads=0 idlethreads=3 runqueue=0 [0 0 0 0 0 0 0 0]
SCHED 4028ms: gomaxprocs=8 idleprocs=7 threads=6 spinningthreads=0 idlethreads=2 runqueue=0 [0 0 0 0 0 0 0 0]
SCHED 5033ms: gomaxprocs=8 idleprocs=5 threads=6 spinningthreads=0 idlethreads=0 runqueue=0 [0 0 0 0 0 0 0 0]
SCHED 6033ms: gomaxprocs=8 idleprocs=3 threads=8 spinningthreads=0 idlethreads=0 runqueue=0 [0 0 0 0 0 0 0 0]
SCHED 7035ms: gomaxprocs=8 idleprocs=0 threads=10 spinningthreads=0 idlethreads=0 runqueue=0 [0 0 0 0 0 0 0 0]
SCHED 8037ms: gomaxprocs=8 idleprocs=0 threads=10 spinningthreads=0 idlethreads=0 runqueue=1 [0 0 0 0 0 0 0 0]
SCHED 9044ms: gomaxprocs=8 idleprocs=0 threads=10 spinningthreads=0 idlethreads=0 runqueue=1 [0 0 0 0 0 0 0 0]
SCHED 10050ms: gomaxprocs=8 idleprocs=0 threads=10 spinningthreads=0 idlethreads=0 runqueue=1 [0 0 0 0 0 0 0 0]
SCHED 11059ms: gomaxprocs=8 idleprocs=0 threads=10 spinningthreads=0 idlethreads=0 runqueue=1 [0 0 0 0 0 0 0 0]
SCHED 12060ms: gomaxprocs=8 idleprocs=0 threads=10 spinningthreads=0 idlethreads=0 runqueue=1 [0 0 0 0 0 0 0 0]
@davecheney

This comment has been minimized.

Copy link
Contributor

commented Sep 19, 2016

Writing infinite loops blocks the go scheduler.

This is not an issue.

We don't the issue tracker to ask questions. Please see https://golang.org/wiki/Questions for good places to ask. Thanks.

@davecheney davecheney closed this Sep 19, 2016

@golang golang locked and limited conversation to collaborators Sep 19, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.