Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

收到非法消息时的一些异常捕获处理. #81

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

收到非法消息时的一些异常捕获处理. #81

wants to merge 1 commit into from

Conversation

JohnSnooow
Copy link

遇到的一些解消息异常处理.

@JohnSnooow
Copy link
Author

JohnSnooow commented Jul 2, 2019

这是在线上遇到过的问题,望大佬看看。

@whtiehack
Copy link
Member

仔细测试了一下,这样只能避免一部分情况,把报错换成一个警告消息而已。
你是什么需求需要改这个?可以描述一下吗?

@JohnSnooow
Copy link
Author

JohnSnooow commented Jul 2, 2019

之前在线上受到攻击,收到大量非法请求包,解包的地方抛出大量的异常, 为了让解包的部分能够捕获到异常,正常运行,不让异常扩散。 出于这个原因增加了两个try。
线上实际上遇到3个地方抛异常,我粗暴的加了两个try来解决。

  1. protos[name].option , protos[name] 为空 抛出异常
  2. pinus-protocol/lib/protocol.ts Message.decode 参数buffer为空, 导致Buffer.from(buffer)抛出异常
  3. pinus-protocol/lib/protocol.ts Message.decode 中 Buffer.alloc(bodyLen) bodyLen为非法的负值导致抛出异常

更合适的做法可能是在这些地方做出一些非法判定, 减少异常的抛出。

@whtiehack
Copy link
Member

我做了一下测试,还是不完整,也不太严谨,还要再思考一下。

@whtiehack
Copy link
Member

还有一个方法,你可以把组件copy到自己项目,替换掉框架自带的组件。
这个PR还需要完善一下。

whtiehack added a commit that referenced this pull request Dec 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants