记一次netty http server给客户端返回reset包排除
2024-09-18 11:02:09
类似文章:解决用netty去做web服务时,post长度过大的问题
现象:当客户端给server发送的请求体较大时,服务直接给客户端返回reset包。
tcpdump:
应用还没有完全收上去,就close这个fd,造成发送reset包。
https://github.com/torvalds/linux/blob/master/net/ipv4/tcp.c#L2384
netstat -s |grep "connections reset due to early user close" 这个计数器一直在增加
因为返回的 RST 包有窗口大小,所以这是主动调用的 tcp_send_active_reset, 代码里有 bug,读缓冲里有数据没读完直接 close 了。
程序里判断如果msg不可读,就把channel close掉。而当请求体过大时,netty会把msg设置为chunked,而chunked的msg也是不可读的,结果就导致了问题:缓冲区还有数据,但不可读,程序就把channel close了,操作系统这时会发送reset包,导致客户端收到reset包。
netty3的HttpRequestDecoder注释:
/**
* Creates a new instance with the default
* {@code maxInitialLineLength (4096}}, {@code maxHeaderSize (8192)}, and
* {@code maxChunkSize (8192)}.
*/
public HttpRequestDecoder() {
}
org.jboss.netty.handler.codec.http.HttpMessageDecoder#decode方法里:
case READ_VARIABLE_LENGTH_CONTENT:
if (buffer.readableBytes() > maxChunkSize || HttpHeaders.is100ContinueExpected(message)) {
// Generate HttpMessage first. HttpChunks will follow.
checkpoint(State.READ_VARIABLE_LENGTH_CONTENT_AS_CHUNKS);
message.setChunked(true);
return message;
}
break;
修复方式,在netty handler pipeline里添加 HttpChunkAggregator
最新文章
- mysql 数据表中查找重复记录
- Linux 配置双机SSH信任
- Contest2037 - CSU Monthly 2013 Oct (Problem J: Scholarship)
- Maven3(笔记二)
- Source not found for AeceManager$$FastClassByCGLIB$$15dcd49c.invoke(int, Object, Object[]) line: not available 问题解决
- SQL Server存储过程和游标有关实例以及相关网址
- IOS touch event animation 转动的风车
- 浅谈Java单例模式
- innobackup增量备份与恢复
- struts异常:Caused by: Parent package is not defined: json-default - [unknown location]解决办法
- Codechef Bear and Clique Distances
- MySql.Data.dll的版本
- IIS7 开发与 管理 编程 之 Microsoft.Web.Administration
- Git 配置命令设置
- PAT甲题题解-1075. PAT Judge (25)-排序
- 用图片做div背景的列表布局 CSS代码
- Python3基础 str translate 将指定字符转换成另一种特定字符
- iOS - 安全
- 【C#/WPF】GridSplitter 分割布局,拖拽控件分隔栏以改变控件尺寸
- HDU 4762 Cut the Cake(高精度)
热门文章
- 【转载】C#手动往DataTable中末尾新增一行数据
- Vue -- 项目报错整理(2):IE报错 - ‘SyntaxError:strict 模式下不允许一个属性有多个定义‘ ,基于vue element-ui页面跳转坑的解决
- python之路第五天
- 在线java堆栈分析工具
- MyBatis的一级缓存、二级缓存演示以及讲解,序列化异常的处理
- idea导入mybatis源码
- springboot 集成百度的唯一ID生成器
- Odoo启动运行参数(script运行参数,不是运行配置文件)
- 将java的jar包作为windows的服务来启动
- ARTS-week8