filesystem: Fix crash when watch callback returns error or throws#42554
Merged
botengyao merged 4 commits intoenvoyproxy:mainfrom Dec 16, 2025
Merged
filesystem: Fix crash when watch callback returns error or throws#42554botengyao merged 4 commits intoenvoyproxy:mainfrom
botengyao merged 4 commits intoenvoyproxy:mainfrom
Conversation
Previously, when a filesystem watch callback returned a non-OK status or threw an exception, the error would propagate to FileEventImpl which uses THROW_IF_NOT_OK. Since there's no exception handler in the libevent loop, this caused std::terminate to be called, crashing Envoy. This change makes the inotify (Linux) and kqueue (macOS) watchers handle callback errors gracefully by: 1. Catching exceptions using TRY_ASSERT_MAIN_THREAD/MULTI_CATCH macros. 2. Logging errors at WARN level instead of propagating them. 3. Always returning OkStatus to the event loop. This improves resilience during config/secret hot reloads where transient errors should not crash the proxy. Risk Level: Medium Testing: Added unit tests for error status and exception handling paths. Signed-off-by: Rohit Agrawal <rohit.agrawal@salesforce.com> Signed-off-by: Rohit Agrawal <rohit.agrawal@databricks.com>
botengyao
reviewed
Dec 15, 2025
Member
botengyao
left a comment
There was a problem hiding this comment.
sorry for the delay, lgtm module the log spam part.
/wait
| absl::StatusOr<PathSplitResult> pathname_or_error = | ||
| file_system_.splitPathFromFilename(file->file_); | ||
| RETURN_IF_NOT_OK_REF(pathname_or_error.status()); | ||
| if (!pathname_or_error.ok()) { |
Member
There was a problem hiding this comment.
A pathname failure is not temporary, will continuing mean you may warn forever on every event and never recover?
Member
Author
There was a problem hiding this comment.
Hmmm, I think a better fix here would be to remove the broken watch.
Signed-off-by: Rohit Agrawal <rohit.agrawal@databricks.com>
Signed-off-by: Rohit Agrawal <rohit.agrawal@databricks.com>
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.
Description
Today, when a filesystem watch callback returns a non-OK status or throws an exception, the error gets propagated to
FileEventImplwhich usesTHROW_IF_NOT_OK.Since there's no exception handler in the
libeventloop, this causesstd::terminateto be called, which crashes Envoy.Stack Trace:
In this change, we are making the
inotifyandkqueuewatchers handle callback errors gracefully by catching any exceptions usingTRY_ASSERT_MAIN_THREAD, logging errors instead of propagating them and always returning theOkStatusto the event loop.Commit Message: filesystem: Fix crash when watch callback returns error or throws
Additional Description: Make
inotifyandkqueuewatchers handle callback errors gracefully.Risk Level: Low
Testing: CI
Docs Changes: N/A
Release Notes: N/A