Skip to content

net/http: should get "ok" but get no response #23336

Closed
@anotherGoogleFan

Description

@anotherGoogleFan

Please answer these questions before submitting your issue. Thanks!

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

go version go1.9.2 linux/amd64
go version go1.9.2 windows/amd64
both got the same problem

Does this issue reproduce with the latest release?

yes

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

one is windows:
$ go env
set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=E:\GoProject
set GORACE=
set GOROOT=C:\Go
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0
set CXX=g++
set CGO_ENABLED=1
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config

one is linux:
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/root/GoProject"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build038803651=/tmp/go-build"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

code is simple enough:

package main

import (
	"context"
	"net/http"
	"os"
	"os/signal"
	"time"

	"github.com/anotherGoogleFan/log"
)

func main() {
	mux := http.NewServeMux()
	mux.Handle("/video/upload", http.HandlerFunc(UploadVideo))
	srv := &http.Server{
		Addr:    ":8848",
		Handler: mux,
	}
	// 如果接收到关闭信号(如 kill -2)则进行graceful shutdown
	go gracefulShutdown(srv)

	// service connections
	if err := srv.ListenAndServe(); err != nil {
		log.Fields{
			"port": "8848",
			"err":  err.Error(),
		}.Error("unexpected service stop")
		return
	}
}

func gracefulShutdown(srv *http.Server) {
	stopChan := make(chan os.Signal)
	signal.Notify(stopChan, os.Interrupt, os.Kill)
	<-stopChan
	log.Info("receive shutdown signal. Ready to exist")
	defer log.Info("program exists")
	ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
	srv.Shutdown(ctx)
}

func UploadVideo(w http.ResponseWriter, r *http.Request) {
	if r.Method != http.MethodPost {
		http.Error(w, "only post allowed", http.StatusMethodNotAllowed)
		return
	}

	http.Error(w, "ok", http.StatusOK)
}

What did you expect to see?

I post a file
uploadwithnoresponse
with chrome plugin postman. I should get the response "ok".

What did you see instead?

No response.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeWaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions