Skip to content

Protect event loop from user callback exceptions#91

Open
VolkerChristian wants to merge 1 commit intomasterfrom
codex/find-best-way-to-handle-exceptions-in-eventloop
Open

Protect event loop from user callback exceptions#91
VolkerChristian wants to merge 1 commit intomasterfrom
codex/find-best-way-to-handle-exceptions-in-eventloop

Conversation

@VolkerChristian
Copy link
Copy Markdown
Member

Motivation

  • Prevent uncaught exceptions in user callbacks from unwinding the event loop and crashing the process.
  • Avoid leaving composite resources (e.g. socket reader/writer pairs) in half-open states when one side throws.
  • Provide a central recovery hook so individual receiver types can implement domain-appropriate teardown behavior.

Description

  • Add a global safety net in core::Event::dispatch that catches all exceptions from onEvent and forwards them to a new recovery hook: EventReceiver::onEventException(std::exception_ptr). (files: src/core/Event.cpp, src/core/EventReceiver.h)
  • Implement a default EventReceiver::onEventException that logs the exception (standard and non-standard) using the logging facility. (file: src/core/EventReceiver.cpp)
  • For descriptor-backed receivers, override the recovery hook so a failing callback causes the receiver to be disabled, preventing repeated failing callbacks on the same fd. (files: src/core/DescriptorEventReceiver.h, src/core/DescriptorEventReceiver.cpp)
  • In socket stream code, override the hook for the SocketReader/SocketWriter paths to route exceptions into the existing error handling path by invoking onStatus(EIO), which triggers the established connection teardown flow and avoids leaving only one side disabled. (files: src/core/socket/stream/SocketReader.{h,cpp}, src/core/socket/stream/SocketWriter.{h,cpp})

Testing

  • Ran git diff --check to verify no whitespace or diff errors, which passed.
  • Ran cmake -S . -B build to validate project configuration; configuration failed in this environment due to a missing external dependency (nlohmann_json>=3.11) unrelated to these code changes, so a full build was not completed here.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant