ZLMediaKit / ZLToolKit

一个基于C++11的轻量级网络框架,基于线程池技术可以实现大并发网络IO
MIT License
1.94k stars 581 forks source link

[BUG] The `onAccept` exception occurred with a write event. #201

Closed baigao-X closed 9 months ago

baigao-X commented 9 months ago

Phenomenon Description

The tested version has completed the patch fix mentioned in issue #2946 in the ZLMediaKit project. However, during testing, a write event still occurred within the onAccept interface.

Analyzing the code, I believe there is a event cache issue mentioned in the epoll man manual. Here is my analysis of the possible logic that triggers the exception (please correct me if my analysis is wrong):

When a write event is thrown to the onAceept callback, it will cause a particularly serious exception (dead loop).

How to reproduce?

It is likely to occur when openRtpServer and closeRtpServerAPi are called frequently.

现象描述

测试的版本已经完成了 ZLMediaKit 项目中issue #2946 中提到的补丁修复。 但是在测试时依然在onAccept接口内出现了write事件。

分析代码我想是存在epoll man手册中提及的 event cache 问题 以下是我分析的可能触发异常逻辑(分析如有不对,请斧正)

当一个写事件抛给onAceept回调时将引起特别严重的异常(死循环)

如何复现?

频繁调用openRtpServer 和closeRtpServerAPi时,有几率发生。

TRANS_BY_GITHUB_AI_ASSISTANT

xia-chu commented 9 months ago

Indeed, this issue exists. However, this issue does not exist in select mode because select mode first traverses and saves PollEventCB. epoll mode does not cache PollEventCB before execution.

确实存在这个问题 不过这个问题在select模式下不存在 因为select模式先遍历并保存PollEventCB epoll模式不会缓存PollEventCB再执行

TRANS_BY_GITHUB_AI_ASSISTANT

baigao-X commented 9 months ago

Indeed, this problem does not exist in the select mode.

However, I think that since delEvent has already been called, it means that the event is no longer relevant, and there is no need to waste time executing the event callback.

Therefore, I still added this filter in the select branch.

确实select模式下不会存在这个问题。 但是我想既然已经调用了delEvent,说明这个事件已经不关心了,也就没必要浪费再去执行这个事件回调了。 因此在select分支中我还是加上了这层过滤。

TRANS_BY_GITHUB_AI_ASSISTANT