Go Env:
goarch=“AMD64”
goroot=“/usr/local/go”
goTooldir=“/usr/local/go/pkg/tool/linux_amd64”
go15vendorexperiment=“1”
go版本GO1.6.3 Linux/AMD64
这个问题发生在高负载的“性能测试环境”库贝-APIServer上。库贝-Apiserver恐慌和退出:
fatal error: concurrent map read and map write
goroutine 77930636 [running]:
runtime.throw(0x2f4c4c0, 0x21)
/root/.gvm/gos/go1.6.3/src/runtime/panic.go:547 +0x90 fp=0xca67b477f0 sp=0xca67b477d8
runtime.mapaccess1_faststr(0x2a8e520, 0xc9e29000f0, 0x2c11220, 0xa, 0x433e360)
/root/.gvm/gos/go1.6.3/src/runtime/hashmap_fast.go:202 +0x5b fp=0xca67b47850 sp=0xca67b477f0
k8s.io/kubernetes/pkg/httplog.(*respLogger).Log(0xcbddf2ae70)
/data/gerrit/src/k8s.io/kubernetes/_output/local/go/src/k8s.io/kubernetes/pkg/httplog/log.go:180 +0x43d fp=0xca67b47af8 sp=0xca67b47850
k8s.io/kubernetes/pkg/apiserver.RecoverPanics.func1(0x7f099f157090, 0xcbddf2ae70, 0xcd7569e380)
/data/gerrit/src/k8s.io/kubernetes/_output/local/go/src/k8s.io/kubernetes/pkg/apiserver/handlers.go:174 +0x15d fp=0xca67b47b50 sp=0xca67b47af8
net/http.HandlerFunc.ServeHTTP(0xc821a4eac0, 0x7f099f157058, 0xca0f4eb450, 0xcd7569e380)
/root/.gvm/gos/go1.6.3/src/net/http/server.go:1618 +0x3a fp=0xca67b47b70 sp=0xca67b47b50
net/http.serverHandler.ServeHTTP(0xc8215a7b80, 0x7f099f157058, 0xca0f4eb450, 0xcd7569e380)
/root/.gvm/gos/go1.6.3/src/net/http/server.go:2081 +0x19e fp=0xca67b47bd0 sp=0xca67b47b70
net/http.(*conn).serve(0xc8b5d6b980)
/root/.gvm/gos/go1.6.3/src/net/http/server.go:1472 +0xf2e fp=0xca67b47f98 sp=0xca67b47bd0
runtime.goexit()
/root/.gvm/gos/go1.6.3/src/runtime/asm_amd64.s:1998 +0x1 fp=0xca67b47fa0 sp=0xca67b47f98
created by net/http.(*Server).Serve
/root/.gvm/gos/go1.6.3/src/net/http/server.go:2137 +0x44e
相应源代码:
145 func RecoverPanics(handler http.Handler) http.Handler {
146 return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
147 defer func() {
148 if x := recover(); x != nil {
149 http.Error(w, "apis panic. Look in log for details.", http.StatusInternalServerError)
150 glog.Errorf("APIServer panic'd on %v %v: %v\n%s\n", req.Method, req.RequestURI, x, debug.Stack())
151 }
152 }()
153 defer httplog.NewLogged(req, &w).StacktraceWhen(
httplog.StatusIsNot(
http.StatusOK,
http.StatusCreated,
http.StatusAccepted,
http.StatusBadRequest,
http.StatusMovedPermanently,
http.StatusTemporaryRedirect,
http.StatusConflict,
http.StatusNotFound,
http.StatusUnauthorized,
http.StatusForbidden,
errors.StatusUnprocessableEntity,
http.StatusSwitchingProtocols,
http.StatusRequestTimeout,
errors.StatusTooManyRequests,
),
170 ).Log()
// Dispatch to the internal handler
handler.ServeHTTP(w, req)
174 })
}
159 func (rl *respLogger) Log() {
160 latency := time.Since(rl.startTime)
161 if glog.V(2) {
162 extraInfo := ""
163 if latency >= time.Millisecond*200 && latency < time.Second {
extraInfo = fmt.Sprintf("%d00.Millisecond", latency/(time.Millisecond*100))
} else if latency >= time.Second && latency < time.Minute { // Warning
extraInfo = fmt.Sprintf("%d.Second", latency/(time.Second))
} else if latency >= time.Minute { // nce will timeout
extraInfo = fmt.Sprintf("%d.Minutes", latency/(time.Minute))
}
method := rl.req.Method
if len(rl.req.Header["Detailed-Method"]) > 0 {
method = rl.req.Header["Detailed-Method"][0]
}
remoteIP := rl.getXForwardIPAdress(rl.req)
if !rl.hijacked {
//glog.InfoDepth(1, fmt.Sprintf("%s %s: (%v) %v%v%v [%s %s]", rl.req.Method, rl.req.RequestURI, latency, rl.status, rl.statusStack, rl.addedInfo, rl.req.Header["User-Agent"], rl.req.RemoteAddr))
180 glog.InfoDepth(1, fmt.Sprintf("%v %s %s: (%sms) %v%v [%s %s]-%s %v", rl.req.Header["X-Requestid"], method, rl.req.RequestURI, GetMilliLatency(latency), rl.status, rl.addedInfo, rl.req.Header["User-Agent"], remoteIP, extraInfo, rl.statusStack))
} else {
//glog.InfoDepth(1, fmt.Sprintf("%s %s: (%v) hijacked [%s %s]", rl.req.Method, rl.req.RequestURI, latency, rl.req.Header["User-Agent"], rl.req.RemoteAddr))
glog.InfoDepth(1, fmt.Sprintf("%v %s %s: (%sms) hijacked [%s %s]-%s", rl.req.Header["X-Requestid"], method, rl.req.RequestURI, GetMilliLatency(latency), rl.req.Header["User-Agent"], remoteIP, extraInfo))
}
}
我的猜测是,您已经注意到这样一个事实,即全局超时处理程序实际上不能阻止goroutines处理请求。因此,当连接超时(1M,除非您已经更改了它)时,它将返回一个错误。如果goroutine实际上同时完成,它也可以尝试写入连接。我以为我们已经添加了一个锁来防止这导致一个问题,但也许标题并不总是受到锁的保护。如果您可以在一个干净的源代码树中复制这个,那么请在Kubernetes github Repo上提交一个问题。
问题内容: 我正在编写自己的logginMiddleware。基本上,我需要记录请求和响应的正文。我面临的问题是,当我阅读正文时,它变成空的,无法两次阅读。我知道发生这种情况是因为它属于ReadCloser类型。有没有一种方法可以将身体重绕到开始? 问题答案: 检查和嘲笑请求正文 初次阅读主体时,必须对其进行存储,以便在处理完该主体之后,可以将新的主体设置为根据原始数据构造的请求主体。因此,当您在
如果收到类型的请求,如何读取特定标头的值?在本例中,我希望从请求头中提取一个jwt令牌的值。
我在多个线程上运行以下方法: HTTP请求是并行处理的吗?以这种方式发出请求是否会阻止其他线程发送请求,直到第一个响应到达?
我使用django rest框架作为后端,并试图使用请求标头中的令牌来验证角请求,但角没有发送任何标头值。我已经尝试了所有的方法添加头请求 访问控制请求标头:访问控制允许标头、访问控制允许来源、授权、内容类型访问控制请求方法:GET DNT:1来源:http://localhost:4001推荐人:http://localhost:4001/
一种写法同时支持 Curl 和 Swoole use \Yurun\Util\YurunHttp\Co\Batch; use \Yurun\Util\HttpRequest; $result = Batch::run([ (new HttpRequest)->url('https://www.imiphp.com'), (new HttpRequest)->url('https:
问题内容: type ValidationModel struct { Name string Email string Password string } 首先,我使用govalidator验证请求正文。 在验证了请求之后,我再次将请求主体解码为用户结构,但已使用validationModel读取了请求主体一次,因此当我尝试再次将其解码为用户时,它没有提供任何值。 我在这里可以想到两种解决方案: