Skip to content

signal: Avoid allocation in fatal signal handler - #48471

Merged
phlax merged 5 commits into
envoyproxy:mainfrom
phlax:signal-death
Oct 21, 2026
Merged

phlax merged 5 commits into
envoyproxy:mainfrom
phlax:signal-death

Conversation

@phlax

@phlax phlax commented Oct 20, 2026

Copy link
Copy Markdown
Member

No description provided.

ravenblackx
ravenblackx previously approved these changes Oct 20, 2026
ravenblackx
ravenblackx previously approved these changes Oct 20, 2026
@phlax

phlax commented Oct 20, 2026

Copy link
Copy Markdown
Member Author

/retest flakey android

jwendell
jwendell previously approved these changes Oct 20, 2026
@phlax

phlax commented Oct 20, 2026

Copy link
Copy Markdown
Member Author

/retest

@phlax

phlax commented Oct 20, 2026

Copy link
Copy Markdown
Member Author

/coverage

@repokitteh-read-only

Copy link
Copy Markdown

Coverage for this Pull Request will be rendered here:

https://storage.googleapis.com/envoy-cncf-pr/48471/coverage/index.html

For comparison, current coverage on main branch is here:

https://storage.googleapis.com/envoy-cncf-postsubmit/main/coverage/index.html

The coverage results are (re-)rendered each time the CI Envoy/Checks (coverage) job completes.

🐱

Caused by: a #48471 (comment) was created by @phlax.

see: more, trace.

@phlax
phlax merged commit f8b232f into envoyproxy:main Oct 21, 2026
27 checks passed
phlax added a commit to phlax/envoy that referenced this pull request Nov 6, 2026
Signed-off-by: Ryan Northey <[email protected]>
(cherry picked from commit f8b232f)
Signed-off-by: Ryan Northey <[email protected]>
phlax added a commit to phlax/envoy that referenced this pull request Nov 9, 2026
This branch does not have coroutine backtraces, so the envoyproxy#48471 entry only applies to native ones.

Signed-off-by: Ryan Northey <[email protected]>
phlax added a commit to phlax/envoy that referenced this pull request Nov 9, 2026
Signed-off-by: Ryan Northey <[email protected]>
(cherry picked from commit f8b232f)
Signed-off-by: Ryan Northey <[email protected]>
phlax added a commit to phlax/envoy that referenced this pull request Nov 11, 2026
Signed-off-by: Ryan Northey <[email protected]>
(cherry picked from commit f8b232f)
Signed-off-by: Ryan Northey <[email protected]>
phlax added a commit to phlax/envoy that referenced this pull request Nov 11, 2026
envoyproxy#49180)

envoyproxy#48471 made the fatal signal handler write fault descriptions and
backtraces directly to stderr, so that it does not re-enter the logger.
The release note describes that as a bug fix, but does not say that the
output no longer reaches configured log sinks such as `--log-path`.

State it explicitly as a minor behavior change, as it matters to anyone
collecting crash backtraces from the log file, in particular when the
fix is backported to a stable branch.

Signed-off-by: Ryan Northey <[email protected]>
phlax added a commit to phlax/envoy that referenced this pull request Nov 11, 2026
Signed-off-by: Ryan Northey <[email protected]>
(cherry picked from commit f8b232f)
Signed-off-by: Ryan Northey <[email protected]>
phlax added a commit that referenced this pull request Nov 11, 2026
#49180)

#48471 made the fatal signal handler write fault descriptions and
backtraces directly to stderr, so that it does not re-enter the logger.
Its release note describes that as a bug fix, but does not say that the
output no longer reaches configured log sinks such as `--log-path`.

This adds a `minor_behavior_changes` entry stating it explicitly, as it
matters to anyone collecting crash backtraces from the log file.

Raised from review of the 1.40 backport (#49174), where a patch release
would otherwise change this silently. To be backported there.


Signed-off-by: Ryan Northey <[email protected]>
jwendell pushed a commit that referenced this pull request Nov 11, 2026
Signed-off-by: Ryan Northey <[email protected]>
(cherry picked from commit f8b232f)
Signed-off-by: Ryan Northey <[email protected]>
jwendell pushed a commit that referenced this pull request Nov 11, 2026
#49180)

#48471 made the fatal signal handler write fault descriptions and
backtraces directly to stderr, so that it does not re-enter the logger.
The release note describes that as a bug fix, but does not say that the
output no longer reaches configured log sinks such as `--log-path`.

State it explicitly as a minor behavior change, as it matters to anyone
collecting crash backtraces from the log file, in particular when the
fix is backported to a stable branch.

Signed-off-by: Ryan Northey <[email protected]>
phlax added a commit to phlax/envoy that referenced this pull request Nov 12, 2026
Signed-off-by: Ryan Northey <[email protected]>
(cherry picked from commit f8b232f)
Signed-off-by: Ryan Northey <[email protected]>
phlax added a commit to phlax/envoy that referenced this pull request Nov 12, 2026
envoyproxy#49180)

envoyproxy#48471 made the fatal signal handler write fault descriptions and
backtraces directly to stderr, so that it does not re-enter the logger.
The release note describes that as a bug fix, but does not say that the
output no longer reaches configured log sinks such as `--log-path`.

State it explicitly as a minor behavior change, as it matters to anyone
collecting crash backtraces from the log file, in particular when the
fix is backported to a stable branch.

Signed-off-by: Ryan Northey <[email protected]>
phlax added a commit to phlax/envoy that referenced this pull request Nov 12, 2026
Signed-off-by: Ryan Northey <[email protected]>
(cherry picked from commit f8b232f)
Signed-off-by: Ryan Northey <[email protected]>
phlax added a commit to phlax/envoy that referenced this pull request Nov 12, 2026
envoyproxy#49180)

envoyproxy#48471 made the fatal signal handler write fault descriptions and
backtraces directly to stderr, so that it does not re-enter the logger.
The release note describes that as a bug fix, but does not say that the
output no longer reaches configured log sinks such as `--log-path`.

State it explicitly as a minor behavior change, as it matters to anyone
collecting crash backtraces from the log file, in particular when the
fix is backported to a stable branch.

Signed-off-by: Ryan Northey <[email protected]>
phlax added a commit to phlax/envoy that referenced this pull request Nov 12, 2026
envoyproxy#48471 took the fatal signal handler's output off the logger, which could
deadlock or abort on the logger mutex, and sent it to `std::cerr`. That
is not async-signal-safe either: iostream output goes through the stdio
lock and is not guaranteed to be allocation free, so a signal arriving
while the same thread is inside a stream or allocator call can still hang
or fault again before the backtrace and the fatal actions run.

Add `StderrWriter`, which builds a line in a fixed buffer and writes it
with a single write(2), and use it for the fault line and for the regular
and coroutine backtraces when they are directed to stderr. The output is
unchanged.

`printTrace()` goes back to taking only a stream, as its prefixed form
was only used for this path.

Signed-off-by: Ryan Northey <[email protected]>
phlax added a commit to phlax/envoy that referenced this pull request Nov 12, 2026
envoyproxy#48471 took the fatal signal handler's output off the logger, which could
deadlock or abort on the logger mutex, and sent it to `std::cerr`. That
is not async-signal-safe either: iostream output goes through the stdio
lock and is not guaranteed to be allocation free, so a signal arriving
while the same thread is inside a stream or allocator call can still hang
or fault again before the backtrace and the fatal actions run.

Add `StderrWriter`, which builds a line in a fixed buffer and writes it
with a single write(2), and use it for the fault line and for the regular
and coroutine backtraces when they are directed to stderr. The output is
unchanged.

`printTrace()` goes back to taking only a stream, as its prefixed form
was only used for this path.

Signed-off-by: Ryan Northey <[email protected]>
phlax added a commit to phlax/envoy that referenced this pull request Nov 12, 2026
Signed-off-by: Ryan Northey <[email protected]>
(cherry picked from commit f8b232f)
Signed-off-by: Ryan Northey <[email protected]>
phlax added a commit to phlax/envoy that referenced this pull request Nov 12, 2026
envoyproxy#49180)

envoyproxy#48471 made the fatal signal handler write fault descriptions and
backtraces directly to stderr, so that it does not re-enter the logger.
The release note describes that as a bug fix, but does not say that the
output no longer reaches configured log sinks such as `--log-path`.

State it explicitly as a minor behavior change, as it matters to anyone
collecting crash backtraces from the log file, in particular when the
fix is backported to a stable branch.

Signed-off-by: Ryan Northey <[email protected]>
phlax added a commit to phlax/envoy that referenced this pull request Nov 12, 2026
envoyproxy#48471 took the fatal signal handler's output off the logger, which could
deadlock or abort on the logger mutex, and sent it to `std::cerr`. That
is not async-signal-safe either: iostream output goes through the stdio
lock and is not guaranteed to be allocation free, so a signal arriving
while the same thread is inside a stream or allocator call can still hang
or fault again before the backtrace and the fatal actions run.

Add `StderrWriter`, which builds a line in a fixed buffer and writes it
with a single write(2), and use it for the fault line and for the regular
and coroutine backtraces when they are directed to stderr. The output is
unchanged.

`printTrace()` goes back to taking only a stream, as its prefixed form
was only used for this path.

Signed-off-by: Ryan Northey <[email protected]>
phlax added a commit to phlax/envoy that referenced this pull request Nov 12, 2026
Signed-off-by: Ryan Northey <[email protected]>
(cherry picked from commit f8b232f)
Signed-off-by: Ryan Northey <[email protected]>
phlax added a commit to phlax/envoy that referenced this pull request Nov 12, 2026
envoyproxy#49180)

envoyproxy#48471 made the fatal signal handler write fault descriptions and
backtraces directly to stderr, so that it does not re-enter the logger.
The release note describes that as a bug fix, but does not say that the
output no longer reaches configured log sinks such as `--log-path`.

State it explicitly as a minor behavior change, as it matters to anyone
collecting crash backtraces from the log file, in particular when the
fix is backported to a stable branch.

Signed-off-by: Ryan Northey <[email protected]>
phlax added a commit to phlax/envoy that referenced this pull request Nov 12, 2026
envoyproxy#48471 took the fatal signal handler's output off the logger, which could
deadlock or abort on the logger mutex, and sent it to `std::cerr`. That
is not async-signal-safe either: iostream output goes through the stdio
lock and is not guaranteed to be allocation free, so a signal arriving
while the same thread is inside a stream or allocator call can still hang
or fault again before the backtrace and the fatal actions run.

Add `StderrWriter`, which builds a line in a fixed buffer and writes it
with a single write(2), and use it for the fault line and for the regular
and coroutine backtraces when they are directed to stderr. The output is
unchanged.

`printTrace()` goes back to taking only a stream, as its prefixed form
was only used for this path.

Signed-off-by: Ryan Northey <[email protected]>
phlax added a commit that referenced this pull request Nov 12, 2026
#48471 took the fatal signal handler's output off the logger, which
could deadlock or abort on the logger mutex, and sent it to `std::cerr`.
That is not async-signal-safe either: iostream output goes through the
stdio lock and is not guaranteed to be allocation free, so a signal
arriving while the same thread is inside a stream or allocator call can
still hang or fault again before the backtrace and the fatal actions
run.

This adds `StderrWriter`, which builds a line in a fixed buffer and
writes it with a single `write(2)`, and uses it for the fault line and
for the regular and coroutine backtraces when they are directed to
stderr. The output is unchanged.

`printTrace()` goes back to taking only a stream, as its prefixed form
was only used for this path.

Not covered: the fatal error handlers that run after the backtrace are
still handed `std::cerr`, as before.

Risk Level: low
Testing: unit test for `StderrWriter`; the existing
`Backward.FaultToStderr`, `Backward.TraceToStderr` and coroutine stderr
tests cover the output format
Docs Changes: n/a
Release Notes: n/a
Platform Specific Features: n/a

---------

Signed-off-by: Ryan Northey <[email protected]>
phlax added a commit to phlax/envoy that referenced this pull request Nov 17, 2026
Signed-off-by: Ryan Northey <[email protected]>
(cherry picked from commit f8b232f)
Signed-off-by: Ryan Northey <[email protected]>
phlax added a commit to phlax/envoy that referenced this pull request Nov 17, 2026
envoyproxy#49180)

envoyproxy#48471 made the fatal signal handler write fault descriptions and
backtraces directly to stderr, so that it does not re-enter the logger.
The release note describes that as a bug fix, but does not say that the
output no longer reaches configured log sinks such as `--log-path`.

State it explicitly as a minor behavior change, as it matters to anyone
collecting crash backtraces from the log file, in particular when the
fix is backported to a stable branch.

(cherry picked from commit 8976dff)

Signed-off-by: Ryan Northey <[email protected]>
phlax added a commit to phlax/envoy that referenced this pull request Nov 17, 2026
Signed-off-by: Ryan Northey <[email protected]>
(cherry picked from commit f8b232f)
Signed-off-by: Ryan Northey <[email protected]>
phlax added a commit to phlax/envoy that referenced this pull request Nov 17, 2026
envoyproxy#49180)

envoyproxy#48471 made the fatal signal handler write fault descriptions and
backtraces directly to stderr, so that it does not re-enter the logger.
The release note describes that as a bug fix, but does not say that the
output no longer reaches configured log sinks such as `--log-path`.

State it explicitly as a minor behavior change, as it matters to anyone
collecting crash backtraces from the log file, in particular when the
fix is backported to a stable branch.

(cherry picked from commit 8976dff)

Signed-off-by: Ryan Northey <[email protected]>
phlax added a commit to phlax/envoy that referenced this pull request Nov 17, 2026
Signed-off-by: Ryan Northey <[email protected]>
(cherry picked from commit f8b232f)
Signed-off-by: Ryan Northey <[email protected]>
phlax added a commit to phlax/envoy that referenced this pull request Nov 17, 2026
envoyproxy#49180)

envoyproxy#48471 made the fatal signal handler write fault descriptions and
backtraces directly to stderr, so that it does not re-enter the logger.
The release note describes that as a bug fix, but does not say that the
output no longer reaches configured log sinks such as `--log-path`.

State it explicitly as a minor behavior change, as it matters to anyone
collecting crash backtraces from the log file, in particular when the
fix is backported to a stable branch.

(cherry picked from commit 8976dff)

Signed-off-by: Ryan Northey <[email protected]>
phlax added a commit that referenced this pull request Nov 17, 2026
Signed-off-by: Ryan Northey <[email protected]>
(cherry picked from commit f8b232f)
Signed-off-by: Ryan Northey <[email protected]>
phlax added a commit that referenced this pull request Nov 17, 2026
#49180)

#48471 made the fatal signal handler write fault descriptions and
backtraces directly to stderr, so that it does not re-enter the logger.
The release note describes that as a bug fix, but does not say that the
output no longer reaches configured log sinks such as `--log-path`.

State it explicitly as a minor behavior change, as it matters to anyone
collecting crash backtraces from the log file, in particular when the
fix is backported to a stable branch.

(cherry picked from commit 8976dff)

Signed-off-by: Ryan Northey <[email protected]>
phlax added a commit to phlax/envoy that referenced this pull request Nov 18, 2026
Signed-off-by: Ryan Northey <[email protected]>
(cherry picked from commit f8b232f)
Signed-off-by: Ryan Northey <[email protected]>
phlax added a commit to phlax/envoy that referenced this pull request Nov 18, 2026
envoyproxy#49180)

envoyproxy#48471 made the fatal signal handler write fault descriptions and
backtraces directly to stderr, so that it does not re-enter the logger.
The release note describes that as a bug fix, but does not say that the
output no longer reaches configured log sinks such as `--log-path`.

State it explicitly as a minor behavior change, as it matters to anyone
collecting crash backtraces from the log file, in particular when the
fix is backported to a stable branch.

(cherry picked from commit 8976dff)

Signed-off-by: Ryan Northey <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants