Repository navigation
signal: Write fatal signal backtraces with write(2) - #49207
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The fixed-buffer formatter changes MSVC pointer formatting, omitting its zero-padded uppercase hexadecimal representation without a 0x prefix and causing two tests to fail on that platform.
1 open issue
What changed in this PR
This PR hardens Envoy’s fatal-signal diagnostics by replacing iostream-based stderr output with a fixed-buffer writer, continuing the work in #48471 to avoid logging-related deadlocks.
Changes:
- Adds
StderrWriterfor buffered stderr writes without allocation or iostream locks. - Migrates fault messages and regular/coroutine backtraces to the writer, simplifying
printTrace(). - Adds formatting, flushing, and truncation tests with build dependencies.
| File | Description |
|---|---|
test/common/common/stderr_writer_test.cc |
Tests formatting, null text, flushing, and truncation. |
test/common/common/BUILD |
Registers the writer’s unit tests. |
source/server/BUILD |
Adds the writer dependency for server backtraces. |
source/server/backtrace.h |
Uses the writer for stderr fault messages and backtraces. |
source/common/coroutine/BUILD |
Adds the writer dependency for coroutine backtraces. |
source/common/coroutine/backtrace.h |
Uses the writer for stderr coroutine backtraces. |
source/common/common/stderr_writer.h |
Implements fixed-buffer formatting and stderr writes. |
source/common/common/BUILD |
Defines the writer library target. |
Review effort: Balanced
1198a3c to
0b84b19
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The tests cover only successful writes, leaving short-write handling, EINTR retries, and buffer reset after permanent errors unverified for fatal-signal diagnostics.
1 open issue
1 resolved since last review
Review effort: Balanced
0b84b19 to
ad37491
Compare
ad37491 to
572d535
Compare
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]>
572d535 to
b3c9b7c
Compare
`writeStderr()` formats a line into a buffer on the stack with `absl::SNPrintF` and writes it with a single write(2), in place of the stream-like writer and its own number formatting. A null faulting address is now shown as `(nil)`. Signed-off-by: Ryan Northey <[email protected]>
The regular and coroutine backtraces wrote their frames to stderr with the same block, which is now `writeStderrFrame()`. Signed-off-by: Ryan Northey <[email protected]>
A line written from the fatal signal handler was lost in part on a short write, and entirely if the write was interrupted. Signed-off-by: Ryan Northey <[email protected]>
There was a problem hiding this comment.
🔵 Needs a closer look
Fatal-signal safety depends on absl::SNPrintF internals unavailable in this checkout, and output tests do not establish allocation or lock freedom, requiring a source audit or interruption-focused validation.
No open issues 🎉
2 resolved since last review
Review effort: Balanced
|
Source-level check of the fatal signal path, against the pinned abseil (
So the backtrace output no longer depends on iostreams, the stdio lock or the allocator, and nothing is worse than before: the output is the same other than a null faulting address showing as Not covered here, and not changed: after the backtraces the handler still passes |
|
/retest because //test/extensions/filters/http/ext_proc/http_client:ext_proc_http_integration_test is a sack. |
|
/retest |
…49215) `ext_proc_http_integration_test` ran with the filter's default message timeout of 200ms, and a 900ms timeout on the HTTP client, both in real time. Under tsan a round trip through the fake side stream server can take longer, the request is then failed with a 504 and never reaches the upstream, and the test fails waiting for the upstream connection and crashes on the stream it did not get. Default both to 5s, as envoyproxy#48964 did for the gRPC fixture. The tests that rely on the message timeout set it to 200ms: the two timeout tests, and the two with a cluster that does not exist, where nothing responds. Seen in CI on envoyproxy#49207 (tsan, `ServerNoRequestHeaderMutation`: `Timed out waiting for new connection`, then a segmentation fault). Testing: `*ServerNoRequestHeaderMutation*` with `--config=tsan` on RBE: | | runs | failed | |---|---|---| | main (0dfc464) | 1000 | 2 | | this change | 3000 | 0 | Risk Level: low (test only) Signed-off-by: Ryan Northey <[email protected]>
…49215) `ext_proc_http_integration_test` ran with the filter's default message timeout of 200ms, and a 900ms timeout on the HTTP client, both in real time. Under tsan a round trip through the fake side stream server can take longer, the request is then failed with a 504 and never reaches the upstream, and the test fails waiting for the upstream connection and crashes on the stream it did not get. Default both to 5s, as envoyproxy#48964 did for the gRPC fixture. The tests that rely on the message timeout set it to 200ms: the two timeout tests, and the two with a cluster that does not exist, where nothing responds. Seen in CI on envoyproxy#49207 (tsan, `ServerNoRequestHeaderMutation`: `Timed out waiting for new connection`, then a segmentation fault). Testing: `*ServerNoRequestHeaderMutation*` with `--config=tsan` on RBE: | | runs | failed | |---|---|---| | main (0dfc464) | 1000 | 2 | | this change | 3000 | 0 | Risk Level: low (test only) Signed-off-by: Ryan Northey <[email protected]>
…49215) `ext_proc_http_integration_test` ran with the filter's default message timeout of 200ms, and a 900ms timeout on the HTTP client, both in real time. Under tsan a round trip through the fake side stream server can take longer, the request is then failed with a 504 and never reaches the upstream, and the test fails waiting for the upstream connection and crashes on the stream it did not get. Default both to 5s, as envoyproxy#48964 did for the gRPC fixture. The tests that rely on the message timeout set it to 200ms: the two timeout tests, and the two with a cluster that does not exist, where nothing responds. Seen in CI on envoyproxy#49207 (tsan, `ServerNoRequestHeaderMutation`: `Timed out waiting for new connection`, then a segmentation fault). Testing: `*ServerNoRequestHeaderMutation*` with `--config=tsan` on RBE: | | runs | failed | |---|---|---| | main (0dfc464) | 1000 | 2 | | this change | 3000 | 0 | Risk Level: low (test only) Signed-off-by: Ryan Northey <[email protected]> (cherry picked from commit 14507a6) Signed-off-by: Ryan Northey <[email protected]>
…49215) `ext_proc_http_integration_test` ran with the filter's default message timeout of 200ms, and a 900ms timeout on the HTTP client, both in real time. Under tsan a round trip through the fake side stream server can take longer, the request is then failed with a 504 and never reaches the upstream, and the test fails waiting for the upstream connection and crashes on the stream it did not get. Default both to 5s, as envoyproxy#48964 did for the gRPC fixture. The tests that rely on the message timeout set it to 200ms: the two timeout tests, and the two with a cluster that does not exist, where nothing responds. Seen in CI on envoyproxy#49207 (tsan, `ServerNoRequestHeaderMutation`: `Timed out waiting for new connection`, then a segmentation fault). Testing: `*ServerNoRequestHeaderMutation*` with `--config=tsan` on RBE: | | runs | failed | |---|---|---| | main (0dfc464) | 1000 | 2 | | this change | 3000 | 0 | Risk Level: low (test only) Signed-off-by: Ryan Northey <[email protected]> (cherry picked from commit 14507a6) Signed-off-by: Ryan Northey <[email protected]>
…49215) `ext_proc_http_integration_test` ran with the filter's default message timeout of 200ms, and a 900ms timeout on the HTTP client, both in real time. Under tsan a round trip through the fake side stream server can take longer, the request is then failed with a 504 and never reaches the upstream, and the test fails waiting for the upstream connection and crashes on the stream it did not get. Default both to 5s, as envoyproxy#48964 did for the gRPC fixture. The tests that rely on the message timeout set it to 200ms: the two timeout tests, and the two with a cluster that does not exist, where nothing responds. Seen in CI on envoyproxy#49207 (tsan, `ServerNoRequestHeaderMutation`: `Timed out waiting for new connection`, then a segmentation fault). Testing: `*ServerNoRequestHeaderMutation*` with `--config=tsan` on RBE: | | runs | failed | |---|---|---| | main (0dfc464) | 1000 | 2 | | this change | 3000 | 0 | Risk Level: low (test only) Signed-off-by: Ryan Northey <[email protected]> (cherry picked from commit 14507a6) Signed-off-by: Ryan Northey <[email protected]>
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 --------- Backport note: lowers the `source/server` coverage threshold to 93.2, as this change takes that directory from 93.3% to 93.2% on this branch. Signed-off-by: Ryan Northey <[email protected]>
…49215) `ext_proc_http_integration_test` ran with the filter's default message timeout of 200ms, and a 900ms timeout on the HTTP client, both in real time. Under tsan a round trip through the fake side stream server can take longer, the request is then failed with a 504 and never reaches the upstream, and the test fails waiting for the upstream connection and crashes on the stream it did not get. Default both to 5s, as envoyproxy#48964 did for the gRPC fixture. The tests that rely on the message timeout set it to 200ms: the two timeout tests, and the two with a cluster that does not exist, where nothing responds. Seen in CI on envoyproxy#49207 (tsan, `ServerNoRequestHeaderMutation`: `Timed out waiting for new connection`, then a segmentation fault). Testing: `*ServerNoRequestHeaderMutation*` with `--config=tsan` on RBE: | | runs | failed | |---|---|---| | main (0dfc464) | 1000 | 2 | | this change | 3000 | 0 | Risk Level: low (test only) Signed-off-by: Ryan Northey <[email protected]> (cherry picked from commit 14507a6) Signed-off-by: Ryan Northey <[email protected]>
…49215) `ext_proc_http_integration_test` ran with the filter's default message timeout of 200ms, and a 900ms timeout on the HTTP client, both in real time. Under tsan a round trip through the fake side stream server can take longer, the request is then failed with a 504 and never reaches the upstream, and the test fails waiting for the upstream connection and crashes on the stream it did not get. Default both to 5s, as envoyproxy#48964 did for the gRPC fixture. The tests that rely on the message timeout set it to 200ms: the two timeout tests, and the two with a cluster that does not exist, where nothing responds. Seen in CI on envoyproxy#49207 (tsan, `ServerNoRequestHeaderMutation`: `Timed out waiting for new connection`, then a segmentation fault). Testing: `*ServerNoRequestHeaderMutation*` with `--config=tsan` on RBE: | | runs | failed | |---|---|---| | main (0dfc464) | 1000 | 2 | | this change | 3000 | 0 | Risk Level: low (test only) Signed-off-by: Ryan Northey <[email protected]> (cherry picked from commit 14507a6) Signed-off-by: Ryan Northey <[email protected]>
…49215) `ext_proc_http_integration_test` ran with the filter's default message timeout of 200ms, and a 900ms timeout on the HTTP client, both in real time. Under tsan a round trip through the fake side stream server can take longer, the request is then failed with a 504 and never reaches the upstream, and the test fails waiting for the upstream connection and crashes on the stream it did not get. Default both to 5s, as envoyproxy#48964 did for the gRPC fixture. The tests that rely on the message timeout set it to 200ms: the two timeout tests, and the two with a cluster that does not exist, where nothing responds. Seen in CI on envoyproxy#49207 (tsan, `ServerNoRequestHeaderMutation`: `Timed out waiting for new connection`, then a segmentation fault). Testing: `*ServerNoRequestHeaderMutation*` with `--config=tsan` on RBE: | | runs | failed | |---|---|---| | main (0dfc464) | 1000 | 2 | | this change | 3000 | 0 | Risk Level: low (test only) Signed-off-by: Ryan Northey <[email protected]> (cherry picked from commit 14507a6) Signed-off-by: Ryan Northey <[email protected]>
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 --------- Backport note: lowers the `source/server` coverage threshold to 93.2, as this change takes that directory from 93.3% to 93.2% on this branch. Signed-off-by: Ryan Northey <[email protected]>
…49215) `ext_proc_http_integration_test` ran with the filter's default message timeout of 200ms, and a 900ms timeout on the HTTP client, both in real time. Under tsan a round trip through the fake side stream server can take longer, the request is then failed with a 504 and never reaches the upstream, and the test fails waiting for the upstream connection and crashes on the stream it did not get. Default both to 5s, as envoyproxy#48964 did for the gRPC fixture. The tests that rely on the message timeout set it to 200ms: the two timeout tests, and the two with a cluster that does not exist, where nothing responds. Seen in CI on envoyproxy#49207 (tsan, `ServerNoRequestHeaderMutation`: `Timed out waiting for new connection`, then a segmentation fault). Testing: `*ServerNoRequestHeaderMutation*` with `--config=tsan` on RBE: | | runs | failed | |---|---|---| | main (0dfc464) | 1000 | 2 | | this change | 3000 | 0 | Risk Level: low (test only) Signed-off-by: Ryan Northey <[email protected]> (cherry picked from commit 14507a6) Signed-off-by: Ryan Northey <[email protected]>
…49215) `ext_proc_http_integration_test` ran with the filter's default message timeout of 200ms, and a 900ms timeout on the HTTP client, both in real time. Under tsan a round trip through the fake side stream server can take longer, the request is then failed with a 504 and never reaches the upstream, and the test fails waiting for the upstream connection and crashes on the stream it did not get. Default both to 5s, as envoyproxy#48964 did for the gRPC fixture. The tests that rely on the message timeout set it to 200ms: the two timeout tests, and the two with a cluster that does not exist, where nothing responds. Seen in CI on envoyproxy#49207 (tsan, `ServerNoRequestHeaderMutation`: `Timed out waiting for new connection`, then a segmentation fault). Testing: `*ServerNoRequestHeaderMutation*` with `--config=tsan` on RBE: | | runs | failed | |---|---|---| | main (0dfc464) | 1000 | 2 | | this change | 3000 | 0 | Risk Level: low (test only) Signed-off-by: Ryan Northey <[email protected]> (cherry picked from commit 14507a6) Signed-off-by: Ryan Northey <[email protected]>
…49215) `ext_proc_http_integration_test` ran with the filter's default message timeout of 200ms, and a 900ms timeout on the HTTP client, both in real time. Under tsan a round trip through the fake side stream server can take longer, the request is then failed with a 504 and never reaches the upstream, and the test fails waiting for the upstream connection and crashes on the stream it did not get. Default both to 5s, as envoyproxy#48964 did for the gRPC fixture. The tests that rely on the message timeout set it to 200ms: the two timeout tests, and the two with a cluster that does not exist, where nothing responds. Seen in CI on envoyproxy#49207 (tsan, `ServerNoRequestHeaderMutation`: `Timed out waiting for new connection`, then a segmentation fault). Testing: `*ServerNoRequestHeaderMutation*` with `--config=tsan` on RBE: | | runs | failed | |---|---|---| | main (0dfc464) | 1000 | 2 | | this change | 3000 | 0 | Risk Level: low (test only) Signed-off-by: Ryan Northey <[email protected]> (cherry picked from commit 14507a6) Signed-off-by: Ryan Northey <[email protected]>
…49215) `ext_proc_http_integration_test` ran with the filter's default message timeout of 200ms, and a 900ms timeout on the HTTP client, both in real time. Under tsan a round trip through the fake side stream server can take longer, the request is then failed with a 504 and never reaches the upstream, and the test fails waiting for the upstream connection and crashes on the stream it did not get. Default both to 5s, as envoyproxy#48964 did for the gRPC fixture. The tests that rely on the message timeout set it to 200ms: the two timeout tests, and the two with a cluster that does not exist, where nothing responds. Seen in CI on envoyproxy#49207 (tsan, `ServerNoRequestHeaderMutation`: `Timed out waiting for new connection`, then a segmentation fault). Testing: `*ServerNoRequestHeaderMutation*` with `--config=tsan` on RBE: | | runs | failed | |---|---|---| | main (0dfc464) | 1000 | 2 | | this change | 3000 | 0 | Risk Level: low (test only) Signed-off-by: Ryan Northey <[email protected]> (cherry picked from commit 14507a6) Signed-off-by: Ryan Northey <[email protected]>
…49215) `ext_proc_http_integration_test` ran with the filter's default message timeout of 200ms, and a 900ms timeout on the HTTP client, both in real time. Under tsan a round trip through the fake side stream server can take longer, the request is then failed with a 504 and never reaches the upstream, and the test fails waiting for the upstream connection and crashes on the stream it did not get. Default both to 5s, as envoyproxy#48964 did for the gRPC fixture. The tests that rely on the message timeout set it to 200ms: the two timeout tests, and the two with a cluster that does not exist, where nothing responds. Seen in CI on envoyproxy#49207 (tsan, `ServerNoRequestHeaderMutation`: `Timed out waiting for new connection`, then a segmentation fault). Testing: `*ServerNoRequestHeaderMutation*` with `--config=tsan` on RBE: | | runs | failed | |---|---|---| | main (0dfc464) | 1000 | 2 | | this change | 3000 | 0 | Risk Level: low (test only) Signed-off-by: Ryan Northey <[email protected]> (cherry picked from commit 14507a6) Signed-off-by: Ryan Northey <[email protected]>
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]>
…49215) `ext_proc_http_integration_test` ran with the filter's default message timeout of 200ms, and a 900ms timeout on the HTTP client, both in real time. Under tsan a round trip through the fake side stream server can take longer, the request is then failed with a 504 and never reaches the upstream, and the test fails waiting for the upstream connection and crashes on the stream it did not get. Default both to 5s, as envoyproxy#48964 did for the gRPC fixture. The tests that rely on the message timeout set it to 200ms: the two timeout tests, and the two with a cluster that does not exist, where nothing responds. Seen in CI on envoyproxy#49207 (tsan, `ServerNoRequestHeaderMutation`: `Timed out waiting for new connection`, then a segmentation fault). Testing: `*ServerNoRequestHeaderMutation*` with `--config=tsan` on RBE: | | runs | failed | |---|---|---| | main (0dfc464) | 1000 | 2 | | this change | 3000 | 0 | Risk Level: low (test only) Signed-off-by: Ryan Northey <[email protected]> (cherry picked from commit 14507a6) Signed-off-by: Ryan Northey <[email protected]>
`ext_proc_http_integration_test` ran with the filter's default message timeout of 200ms, and a 900ms timeout on the HTTP client, both in real time. Under tsan a round trip through the fake side stream server can take longer, the request is then failed with a 504 and never reaches the upstream, and the test fails waiting for the upstream connection and crashes on the stream it did not get. Default both to 5s, as #48964 did for the gRPC fixture. The tests that rely on the message timeout set it to 200ms: the two timeout tests, and the two with a cluster that does not exist, where nothing responds. Seen in CI on #49207 (tsan, `ServerNoRequestHeaderMutation`: `Timed out waiting for new connection`, then a segmentation fault). Testing: `*ServerNoRequestHeaderMutation*` with `--config=tsan` on RBE: | | runs | failed | |---|---|---| | main (0dfc464) | 1000 | 2 | | this change | 3000 | 0 | Risk Level: low (test only) Signed-off-by: Ryan Northey <[email protected]>
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 --------- Backport note: lowers the `source/server` coverage threshold to 93.2, as this change takes that directory from 93.3% to 93.2% on this branch. (cherry picked from commit 1e35e9c) Signed-off-by: Ryan Northey <[email protected]>
…49215) `ext_proc_http_integration_test` ran with the filter's default message timeout of 200ms, and a 900ms timeout on the HTTP client, both in real time. Under tsan a round trip through the fake side stream server can take longer, the request is then failed with a 504 and never reaches the upstream, and the test fails waiting for the upstream connection and crashes on the stream it did not get. Default both to 5s, as envoyproxy#48964 did for the gRPC fixture. The tests that rely on the message timeout set it to 200ms: the two timeout tests, and the two with a cluster that does not exist, where nothing responds. Seen in CI on envoyproxy#49207 (tsan, `ServerNoRequestHeaderMutation`: `Timed out waiting for new connection`, then a segmentation fault). Testing: `*ServerNoRequestHeaderMutation*` with `--config=tsan` on RBE: | | runs | failed | |---|---|---| | main (0dfc464) | 1000 | 2 | | this change | 3000 | 0 | Risk Level: low (test only) Signed-off-by: Ryan Northey <[email protected]> (cherry picked from commit 14507a6) Signed-off-by: Ryan Northey <[email protected]>
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 --------- Backport note: lowers the `source/server` coverage threshold to 93.2, as this change takes that directory from 93.3% to 93.2% on this branch. (cherry picked from commit 1e35e9c) Signed-off-by: Ryan Northey <[email protected]>
…49215) `ext_proc_http_integration_test` ran with the filter's default message timeout of 200ms, and a 900ms timeout on the HTTP client, both in real time. Under tsan a round trip through the fake side stream server can take longer, the request is then failed with a 504 and never reaches the upstream, and the test fails waiting for the upstream connection and crashes on the stream it did not get. Default both to 5s, as envoyproxy#48964 did for the gRPC fixture. The tests that rely on the message timeout set it to 200ms: the two timeout tests, and the two with a cluster that does not exist, where nothing responds. Seen in CI on envoyproxy#49207 (tsan, `ServerNoRequestHeaderMutation`: `Timed out waiting for new connection`, then a segmentation fault). Testing: `*ServerNoRequestHeaderMutation*` with `--config=tsan` on RBE: | | runs | failed | |---|---|---| | main (0dfc464) | 1000 | 2 | | this change | 3000 | 0 | Risk Level: low (test only) Signed-off-by: Ryan Northey <[email protected]> (cherry picked from commit 14507a6) Signed-off-by: Ryan Northey <[email protected]>
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 --------- (cherry picked from commit 1e35e9c) Signed-off-by: Ryan Northey <[email protected]>
…49215) `ext_proc_http_integration_test` ran with the filter's default message timeout of 200ms, and a 900ms timeout on the HTTP client, both in real time. Under tsan a round trip through the fake side stream server can take longer, the request is then failed with a 504 and never reaches the upstream, and the test fails waiting for the upstream connection and crashes on the stream it did not get. Default both to 5s, as envoyproxy#48964 did for the gRPC fixture. The tests that rely on the message timeout set it to 200ms: the two timeout tests, and the two with a cluster that does not exist, where nothing responds. Seen in CI on envoyproxy#49207 (tsan, `ServerNoRequestHeaderMutation`: `Timed out waiting for new connection`, then a segmentation fault). Testing: `*ServerNoRequestHeaderMutation*` with `--config=tsan` on RBE: | | runs | failed | |---|---|---| | main (0dfc464) | 1000 | 2 | | this change | 3000 | 0 | Risk Level: low (test only) Signed-off-by: Ryan Northey <[email protected]> (cherry picked from commit 14507a6) Signed-off-by: Ryan Northey <[email protected]>
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 --------- Backport note: lowers the `source/server` coverage threshold to 93.2, as this change takes that directory from 93.3% to 93.2% on this branch. (cherry picked from commit 1e35e9c) Signed-off-by: Ryan Northey <[email protected]>
`ext_proc_http_integration_test` ran with the filter's default message timeout of 200ms, and a 900ms timeout on the HTTP client, both in real time. Under tsan a round trip through the fake side stream server can take longer, the request is then failed with a 504 and never reaches the upstream, and the test fails waiting for the upstream connection and crashes on the stream it did not get. Default both to 5s, as #48964 did for the gRPC fixture. The tests that rely on the message timeout set it to 200ms: the two timeout tests, and the two with a cluster that does not exist, where nothing responds. Seen in CI on #49207 (tsan, `ServerNoRequestHeaderMutation`: `Timed out waiting for new connection`, then a segmentation fault). Testing: `*ServerNoRequestHeaderMutation*` with `--config=tsan` on RBE: | | runs | failed | |---|---|---| | main (0dfc464) | 1000 | 2 | | this change | 3000 | 0 | Risk Level: low (test only) Signed-off-by: Ryan Northey <[email protected]> (cherry picked from commit 14507a6) Signed-off-by: Ryan Northey <[email protected]>
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 --------- (cherry picked from commit 1e35e9c) Signed-off-by: Ryan Northey <[email protected]>
…49215) `ext_proc_http_integration_test` ran with the filter's default message timeout of 200ms, and a 900ms timeout on the HTTP client, both in real time. Under tsan a round trip through the fake side stream server can take longer, the request is then failed with a 504 and never reaches the upstream, and the test fails waiting for the upstream connection and crashes on the stream it did not get. Default both to 5s, as envoyproxy#48964 did for the gRPC fixture. The tests that rely on the message timeout set it to 200ms: the two timeout tests, and the two with a cluster that does not exist, where nothing responds. Seen in CI on envoyproxy#49207 (tsan, `ServerNoRequestHeaderMutation`: `Timed out waiting for new connection`, then a segmentation fault). Testing: `*ServerNoRequestHeaderMutation*` with `--config=tsan` on RBE: | | runs | failed | |---|---|---| | main (0dfc464) | 1000 | 2 | | this change | 3000 | 0 | Risk Level: low (test only) Signed-off-by: Ryan Northey <[email protected]> (cherry picked from commit 14507a6) Signed-off-by: Ryan Northey <[email protected]>
#49207 introduced a unix write to stderr_writer. This adds a win32 branch to fix compilation on it Example failure: https://github.com/curioswitch/py-envoy-server/actions/runs/43867024431/job/133298099621 @yanavlasov BTW will you add daily sync / builds to envoy-windows repo? Risk Level: low Testing: none Docs Changes: Release Notes: Platform Specific Features: [Optional Runtime guard:] [Optional Fixes #Issue] [Optional Fixes commit #PR or SHA] [Optional Deprecated:] [Optional [API Considerations](https://github.com/envoyproxy/envoy/blob/main/api/review_checklist.md):] Signed-off-by: Anuraag Agrawal <[email protected]>


#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 singlewrite(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 existingBackward.FaultToStderr,Backward.TraceToStderrand coroutine stderr tests cover the output formatDocs Changes: n/a
Release Notes: n/a
Platform Specific Features: n/a