fix(timer): use begin() instead of rbegin() in resetArriveTime()#75
Open
songshu8848 wants to merge 1 commit into
Open
fix(timer): use begin() instead of rbegin() in resetArriveTime()#75songshu8848 wants to merge 1 commit into
songshu8848 wants to merge 1 commit into
Conversation
|
您好,已收到您的来信,谢谢!
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug描述:
tinyrpc/net/timer.cc 文件中 Timer::resetArriveTime()函数可能存在一个逻辑问题,当前实现使用 tmp.rbegin()(反向迭代器)获取队列中最晚的定时任务来设置 timerfd 的触发时间。这会导致当队列中存在多个不同时间的定时任务时,timerfd 总是被设置为在最晚的任务到期时才触发,而中间应该提前执行的定时任务会被延迟执行。
具体场景:
假设队列中已有任务 A(200ms 到期)和 B(400ms 到期),当前实现会取 B(400ms)设置 timerfd,导致任务 A 实际上延迟到 400ms 才执行,延迟了 200ms。
建议修复:
将第100行的 auto it = tmp.rbegin();修改为 auto it = tmp.begin();使 timerfd 跟踪最早到期的任务。
验证依据:
addTimerEvent()中判断是否需要重置 timerfd 的逻辑使用的是 m_pending_events.begin()(最早事件),两者应保持一致。