refactor: remove try/catch from event dispatch and IOCP completion handlers#5
Merged
Merged
Conversation
…ndlers Per project convention, exception-based error handling is not used. All event handlers (HandleRead/Write/Error/Close) and IOCP completion callbacks communicate errors via return values and LMNET_LOG*, not exceptions. Remove the try/catch wrappers from: - darwin kqueue EventReactor::Run() - linux epoll EventReactor::DispatchEvent() - windows IocpManager worker thread Agent-Logs-Url: https://github.com/lmshao/lmnet/sessions/f7bca67d-7d38-40f2-96d7-6f7703e6565e Co-authored-by: lmshao <3686112+lmshao@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
lmshao
May 10, 2026 16:16
View session
There was a problem hiding this comment.
Pull request overview
This PR removes try/catch wrappers from the platform-specific event dispatch paths (kqueue/epoll) and the Windows IOCP worker loop to align reactor/IO completion handling with the project’s stated no-exceptions convention.
Changes:
- Removed
try/catcharound kqueue dispatch in the Darwin reactor run loop. - Removed
try/catcharound handler invocations in the Linux epollDispatchEvent()path. - Removed
try/catcharoundHandleCompletion()in the Windows IOCP worker thread and assignsrecycleRequestdirectly from the return value.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/platforms/darwin/event_reactor.cpp | Removes exception wrapper around kqueue event dispatch. |
| src/platforms/linux/epoll/event_reactor.cpp | Removes exception wrapper around epoll handler calls in DispatchEvent(). |
| src/platforms/windows/iocp_manager.cpp | Removes exception wrapper around IOCP completion handling in the worker loop. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
203
to
206
| // Handle completion | ||
| bool recycleRequest = true; | ||
| try { | ||
| recycleRequest = HandleCompletion(req, bytes, error); | ||
| } catch (const std::exception &e) { | ||
| LMNET_LOGE("Exception in IOCP completion handler: %s", e.what()); | ||
| } catch (...) { | ||
| LMNET_LOGE("Unknown exception in IOCP completion handler"); | ||
| } | ||
| bool recycleRequest = HandleCompletion(req, bytes, error); | ||
|
|
||
| if (recycleRequest) { |
Comment on lines
+279
to
+283
| if (events & EPOLLIN) { | ||
| handler->HandleRead(fd); | ||
| } | ||
|
|
||
| if (events & EPOLLOUT) { | ||
| handler->HandleWrite(fd); | ||
| } | ||
| if (events & EPOLLOUT) { |
Comment on lines
138
to
140
| if (handler) { | ||
| try { | ||
| DispatchEvent(std::move(handler), kev); | ||
| } catch (const std::exception &e) { | ||
| LMNET_LOGE("Exception in event handler for fd %lld: %s", static_cast<long long>(kev.ident), | ||
| e.what()); | ||
| } catch (...) { | ||
| LMNET_LOGE("Unknown exception in event handler for fd %lld", static_cast<long long>(kev.ident)); | ||
| } | ||
| DispatchEvent(std::move(handler), kev); | ||
| } |
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.
The codebase follows a no-exception convention — handlers communicate errors via return values and
LMNET_LOG*, never by throwing. The try/catch blocks in the event reactor dispatch paths and the IOCP worker thread were dead code that added noise and inconsistency.Changes
src/platforms/darwin/event_reactor.cpp— removed try/catch wrapper aroundDispatchEvent()in the kqueue run loopsrc/platforms/linux/epoll/event_reactor.cpp— removed try/catch wrapper insideDispatchEvent()around the four handler callssrc/platforms/windows/iocp_manager.cpp— removed try/catch wrapper aroundHandleCompletion()in the IOCP worker thread;recycleRequestis now assigned directly from the return value