任何获取'http:response.WriteHeader劫持连接'错误的堆栈跟踪的方法? [英] Any way to get a stack trace for 'http: response.WriteHeader on hijacked connection' errors?

查看:995
本文介绍了任何获取'http:response.WriteHeader劫持连接'错误的堆栈跟踪的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的Web应用程序正在将大量'http:response.WriteHeader on hijacked connection'消息记录到stderr。



有没有办法使< c $ c> http 库会输出一个堆栈跟踪或附加的调试信息以及此消息(或将其升级为错误),以便能够跟踪我们的应用程序中发生这种情况的位置由于错误永远不会被返回,并直接写入到 http.Server.ErrorLog 中, / code>,那是你唯一可以拦截它的地方。



你可以在调试器中运行它并在那个时候中断,但这可能不是



您可以使用<$ c创建一个新的 * log.Logger $ c> io.Writer 它在遇到特定消息时将堆栈跟踪添加到输出。

  type stackWriter struct {
w io.Writer
}
func(s stackWriter)Write (d [] byte)(int,error){
if bytes.Contains(d,[] byte(WriteHeader on hijacked connection)){
swWrite(debug.Stack())
}
return swWrite(d)
}

另一个选项当然是修改 net / http / server.go 来打印当前的堆栈。


Our web application is logging a large number of 'http: response.WriteHeader on hijacked connection' messages to stderr.

Is there any way to make the http library output a stack trace, or additional debugging information, along with this message, (or upgrade it to an error) to make it possible to track down where in our application this is occurring?

解决方案

Since the error is never returned, and written directly to the http.Server.ErrorLog, that is the only place you could intercept it.

You can run it in a debugger and break at that point, but that may not be useful if this is running in production.

You can create a new *log.Logger with an io.Writer which adds the stack trace to the output when it encounters that particular message.

type stackWriter struct {
    w io.Writer
}
func (s stackWriter) Write(d []byte) (int, error) {
    if bytes.Contains(d, []byte("WriteHeader on hijacked connection")) {
        s.w.Write(debug.Stack())
    }
    return s.w.Write(d)
}

Another option of course is to modify net/http/server.go to print the stack at that point.

这篇关于任何获取'http:response.WriteHeader劫持连接'错误的堆栈跟踪的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆