sofastack / sofa-rpc-node

SOFARPC Node is a high-performance, high-extensibility, production-level Nodejs RPC framework.
MIT License
612 stars 64 forks source link

fix: premature close #78

Closed whxaxes closed 3 years ago

whxaxes commented 3 years ago
Checklist
Affected core subsystem(s)
Description of change

直接调用 destroy 会有概率触发 end-of-stream 里( pump 依赖 )的下面这个判断抛出 premature close 错误( 原因是 destroy 之后触发 close 事件时未 ended )。

image

如果未抛异常的情况下应该执行 end 而不是 destroy ,因为 socket 的 autoDestroy 是 true ,所以使用 end 能保证 FIN 包发完后再自动执行 destroy 。

mansonchor commented 3 years ago

lint 挂了

gxcsoccer commented 3 years ago

为啥是从 sofastack:1.x 拉的分支?

whxaxes commented 3 years ago

@gxcsoccer 现在内部好像都还在用 1.x

whxaxes commented 3 years ago

貌似默认 autoDestroy 是 true

@gxcsoccer 是的,Socket 的 autoDestroy 固定是 true 的,所以现在改了,如果有 err 才 destroy ,否则就 end

whxaxes commented 3 years ago

单测还是挂的,我再看一下

whxaxes commented 3 years ago

发现这个问题仅是 sofa-rpc-node 改了还没用 .... pump 那边的设计也有问题,socket 关掉后关联的 stream 也会被 pump 强行 destroy 从而触发 end-of-stream 里的 premature close

https://github.com/mafintosh/pump/issues/25

whxaxes commented 3 years ago

这个我先关了,我再想想其他法子 ...