go net/http: server通过ConnContext钩子设置TCPConn writebuf将阻塞发送大型响应体

p4tfgftt  于 5个月前  发布在  Go
关注(0)|答案(5)|浏览(51)

你正在使用的Go版本是什么( go version )?

1.17.6

这个问题在最新版本中是否会重现?

yes

你正在使用什么操作系统和处理器架构( go env )?

go env 输出

linux amd64

你做了什么?

&http.Server{
	ReadTimeout:    time.Second,
	IdleTimeout:    time.Second,
	MaxHeaderBytes: 1024,
	ConnContext: func(ctx context.Context, conn net.Conn) context.Context {
		(conn.(*net.TCPConn)).SetReadBuffer(2048)
		(conn.(*net.TCPConn)).SetWriteBuffer(2048)
		return ctx
	},
}
use this server and write 12K+ data to response's body
but only 4096 data send
same code,but set the buf to 4096,all data will be send
but when i send 1M+ data when the buf is set to 4096,the send data truncate too
why?

这是tcpdump文件
wireshark过滤器是 tcp.stream eq 18
pod-capture.cap.zip

你期望看到什么?

all data should be send

你实际看到了什么?

it will block on tcp write,and only part of the data will be send
qgelzfjb

qgelzfjb2#

翻译结果为:这是来自pprof的一个请求的跟踪信息。它在G1069312上运行,最后阻塞在internal/pool.(*FD).Write():283,这60秒内没有更多的跟踪信息。

$x_{1e0f1}^{x}$

2skhul33

2skhul333#

这是来自pprof的请求的profile信息。
profile.zip

osh3o9ms

osh3o9ms4#

这是我的自我追踪信息
开始时间是我收到请求的时间
结束时间是Write返回的时间

[TRACE] {"trace_id":"1643164511883031560_7626180989541976002","deep":1,"start":1643164511883037729,"end":1643165625828797709,"host_name":"supports-service-77cc9b447f-4btjv","role":"server","from_app":"unknown","from_ip":"10.136.207.227:23366","from_method":"unknown","from_path":"unknown","to_app":"psp-prod.supports","to_ip":"10.136.192.250","to_method":"POST","to_path":"/supports.gamelog/SearchLog","err_msg":"","err_code":0}
cngwdvgl

cngwdvgl5#

如果删除

(conn.(*net.TCPConn)).SetReadBuffer(2048)
(conn.(*net.TCPConn)).SetWriteBuffer(2048)

一切正常
这里是从pprof中删除后的跟踪信息
trace-delete-set-buf.zip
为什么?

相关问题