Repository navigation
reverse_tunnel: add lifecycle access logging - #44298
Conversation
|
CC @envoyproxy/api-shepherds: Your approval is needed for changes made to |
|
cc: @ivpr |
4ee916f to
280ebee
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces lifecycle access logging for reverse tunnels. It adds an access_log configuration field to the upstream reverse connection socket interface and implements a new upstream network filter, envoy.filters.upstream_network.reverse_tunnel_lifecycle, to capture post-handoff events such as HTTP/2 keepalive timeouts. The implementation includes a new ReverseTunnelLifecycleInfo structure for metadata tracking and updates to the UpstreamSocketManager to support deferred logging. Feedback suggests addressing potential risks associated with raw file descriptor tracking and ensuring that the deferred logging logic has a fallback mechanism to prevent missing log entries if the filter fails to report a close reason.
| return Network::FilterStatus::Continue; | ||
| } | ||
|
|
||
| fd_ = socket->ioHandle().fdDoNotUse(); |
There was a problem hiding this comment.
Using fdDoNotUse() is generally discouraged in Envoy as it bypasses the IoHandle abstraction. While it is used here to index into the UpstreamSocketManager maps, ensure that the file descriptor is guaranteed to be valid and unique for the duration of the lifecycle tracking. If the IoHandle is closed and the FD is recycled before the manager is notified, it could lead to incorrect metadata association.
There was a problem hiding this comment.
The usage is safe here for four reasons: (1) the lifecycle filter is a connection callback, so the socket is guaranteed alive during onNewConnection() and
onEvent(); (2) UpstreamReverseConnectionIOHandle::close() calls markSocketDead(fd_) before releasing the socket, preventing FD recycling before cleanup; (3)
each worker thread has its own UpstreamSocketManager, eliminating cross-thread races; (4) all reverse tunnel FD-indexed maps follow this same ownership pattern.
Added a comment documenting these invariants.
| const bool defer_close_log = lifecycle.handed_off_to_upstream && | ||
| lifecycle.upstream_lifecycle_filter_attached && | ||
| !lifecycle.close_log_emitted && lifecycle.close_reason.empty(); |
There was a problem hiding this comment.
The logic for defer_close_log assumes that if a lifecycle filter is attached, it will eventually provide a close reason. If the filter fails to report a reason (e.g., due to an unexpected connection state or filter chain termination), the tunnel_closed log might be permanently deferred, leading to missing access log entries. Consider adding a fallback mechanism or a timeout to ensure the log is eventually emitted.
There was a problem hiding this comment.
Valid concern. Added a fallback in ~UpstreamSocketManager() that emits any remaining un-emitted tunnel_closed logs with explicit_close reason before the
extension is nulled out. This covers the case where a lifecycle filter never fires (e.g., during shutdown or unexpected connection teardown). Added a test for
this.
|
CC @envoyproxy/coverage-shephards: FYI only for changes made to |
| inline constexpr absl::string_view kFilterStateFd = "envoy.reverse_tunnel.fd"; | ||
|
|
||
| inline constexpr absl::string_view kLifecycleEventTunnelSetup = "tunnel_setup"; | ||
| inline constexpr absl::string_view kLifecycleEventIdlePingSent = "idle_ping_sent"; |
There was a problem hiding this comment.
Doesn't seem like these are implemented?
There was a problem hiding this comment.
Implemented the four idle ping events — idle_ping_sent in sendPingForConnection(), idle_ping_ack in onPingResponse(), idle_ping_miss and idle_ping_timeout in
onPingTimeout() (with miss_count metadata). Removed http2_keepalive_ping_sent and http2_keepalive_ping_ack — those require HTTP/2 codec-layer hooks that are
outside this extension's scope. Updated docs accordingly.
| StreamInfo::StreamInfoImpl stream_info(time_source, connection_info_provider, | ||
| StreamInfo::FilterState::LifeSpan::Connection); | ||
| if (lifecycle.fd >= 0) { | ||
| connection_info_provider->setConnectionID(lifecycle.fd); |
There was a problem hiding this comment.
Is this needed? The connection ID is supposed to be a monotonically increasing identifier for the connection, but FDs can be reused.
There was a problem hiding this comment.
Good catch — removed it. FDs are recycled by the OS so they're not valid connection IDs. The FD is already available in dynamic metadata (fd field) and filter
state (envoy.reverse_tunnel.fd) for log correlation, so %CONNECTION_ID% isn't needed on these synthetic entries.
|
/lgtm api |
dd4f684 to
2fd012b
Compare
phlax
left a comment
There was a problem hiding this comment.
thanks @roll-no-21 - some docs review
|
|
||
| **Idle-phase ping events** (emitted while the socket is idle in the cache): | ||
|
|
||
| * ``idle_ping_sent`` – an RPING probe was sent to verify the idle connection is alive. |
There was a problem hiding this comment.
| * ``idle_ping_sent`` – an RPING probe was sent to verify the idle connection is alive. | |
| * ``idle_ping_sent`` – an ``RPING`` probe was sent to verify the idle connection is alive. |
There was a problem hiding this comment.
Done — wrapped RPING in double backticks here and in all similar references below (idle_ping_ack, idle_ping_miss, idle_ping_timeout, and the close-reason descriptions).
|
|
||
| .. code-block:: yaml | ||
|
|
||
| bootstrap_extensions: |
There was a problem hiding this comment.
this should be in a literalinclude
i was hesitant to say this as im not clear whether the current validation works with bootstrap_extensions (altho have a feeling that it may have just been fixed)
if the validator does not support it - we can exclude it from validation - either way lets put this to a full bootstrap file
There was a problem hiding this comment.
Done — extracted both inline YAML code blocks intodocs/root/_configs/reverse_connection/responder-envoy.yaml and replaced them withliteralinclude directives. The bootstrap access-log config is at lines 7–24 of that file, so the docs config validator can verify it.
| .. code-block:: yaml | ||
|
|
||
| clusters: | ||
| - name: reverse_connection_cluster |
There was a problem hiding this comment.
similar here - this should be a literalinclude
There was a problem hiding this comment.
Done — same as above, this block is now a literalinclude referencing responder-envoy.yaml lines 104–129.
|
@RyanTheOptimist could you take a look please |
| source/extensions/api_listeners: 55.0 # Many IS_ENVOY_BUG are not covered. | ||
| source/extensions/api_listeners/default_api_listener: 67.8 # Many IS_ENVOY_BUG are not covered. | ||
| source/extensions/bootstrap/reverse_tunnel/downstream_socket_interface: 96.3 | ||
| source/extensions/bootstrap/reverse_tunnel/upstream_socket_interface: 95.4 # Lifecycle logging conditional paths |
There was a problem hiding this comment.
Is it possible to add unit tests which cover these codepaths?
There was a problem hiding this comment.
Added comprehensive unit tests covering all lifecycle logging paths — the coverage exception has been removed. The upstream_socket_interface directory has no entry in coverage.yaml now. Tests are in reverse_tunnel_upstream_lifecycle_test.cc (11 tests for the filter) and upstream_socket_manager_test.cc (lifecycle-specific tests for tunnel_setup, socket_handoff tunnel_closed, idle ping events, and deferred close logs).
There was a problem hiding this comment.
Thanks! Coverage LGTM.
|
@roll-no-21 looks like there are a few review comments to be addressed /wait |
|
/retest |
Signed-off-by: Krishna Sharma <[email protected]> Signed-off-by: Krishna Sharma <[email protected]>
a0cd9ac to
6a6c9b3
Compare
|
/retest |
1 similar comment
|
/retest |
|
/retest |
1 similar comment
|
/retest |
|
This passed API and coverage review and waiting for code review. |
Emit structured lifecycle records for tunnel setup, handoff, close, and post-handoff HTTP/2 keepalive timeouts so reverse-tunnel behavior can be debugged from access logs without relying on codec changes. <!-- !!!ATTENTION!!! If you are fixing *any* crash or *any* potential security issue, *do not* open a pull request in this repo. Please report the issue via emailing [email protected] where the issue will be triaged appropriately. Thank you in advance for helping to keep Envoy secure. !!!ATTENTION!!! For an explanation of how to fill out the fields, please see the relevant section in [PULL_REQUESTS.md](https://github.com/envoyproxy/envoy/blob/main/PULL_REQUESTS.md) !!!ATTENTION!!! Please check the [use of generative AI policy](https://github.com/envoyproxy/envoy/blob/main/CONTRIBUTING.md?plain=1#L41). You may use generative AI only if you fully understand the code. You need to disclose this usage in the PR description to ensure transparency. --> Commit Message: reverse_tunnel: add lifecycle access logging Additional Description: Today, debugging reverse tunnel connection issues (silent drops, keepalive timeouts, unexpected closes) requires correlating codec-level debug logs across multiple threads and connections. This PR adds first-class access log support to the reverse tunnel upstream socket interface so that operators can observe the full tunnel lifecycle from structured, machine-parseable access logs. **Proto change (`UpstreamReverseConnectionSocketInterface`)** A new `repeated config.accesslog.v3.AccessLog access_log = 6` field is added to the bootstrap config. When configured, lifecycle events are emitted through the standard Envoy access log framework. No logs are emitted when the field is absent — fully backward compatible. **Lifecycle info struct (`ReverseTunnelLifecycleInfo`)** A new `reverse_tunnel_lifecycle_info.h` header defines: - `ReverseTunnelLifecycleInfo` — per-socket metadata carried through the tunnel lifetime: `node_id`, `cluster_id`, `tenant_id`, local/remote addresses, worker name, file descriptor, and state flags (`handed_off_to_upstream`, `upstream_lifecycle_filter_attached`, `socket_dead_notified`, `close_log_emitted`, `close_reason`). - Well-known string constants for all lifecycle events, socket states, handoff kinds, close reasons, filter-state keys, and the dynamic metadata namespace. **Lifecycle events emitted** Each access log record is written into the `envoy.reverse_tunnel.lifecycle` dynamic metadata namespace with these fields: | Field | Description | |----------------|---------------------------------------------------------------| | `event` | One of the event names below. | | `node_id` | Originating node identifier. | | `cluster_id` | Originating cluster identifier. | | `tenant_id` | Tenant identifier (empty when tenant isolation is off). | | `worker` | Envoy worker thread that owns the socket. | | `fd` | File descriptor number. | | `socket_state` | `idle`, `handed_off`, or `in_use`. | | `handoff_kind` | Present only on `socket_handoff`: `pool_to_upstream`. | | `close_reason` | Present only on `tunnel_closed` (see close reasons below). | The same node/cluster/tenant/worker/fd values are also written into connection filter state under `envoy.reverse_tunnel.*` keys so they can be referenced in `%FILTER_STATE(...)%` format strings. *Core lifecycle events:* - `tunnel_setup` — reverse tunnel accepted and cached. - `socket_handoff` — idle socket handed off to the upstream connection pool. - `tunnel_closed` — socket removed from tracking (final event for every tunnel). - `http2_keepalive_timeout` — upstream closed locally due to HTTP/2 PING timeout after handoff. *Idle-phase ping events (while socket is cached):* - `idle_ping_sent` / `idle_ping_ack` / `idle_ping_miss` / `idle_ping_timeout` *Post-handoff HTTP/2 keepalive events:* - `http2_keepalive_ping_sent` / `http2_keepalive_ping_ack` *Close reason values on `tunnel_closed`:* - `idle_peer_close` — peer closed while idle. - `idle_read_error` — read error on the idle socket. - `idle_ping_write_failure` — RPING write failed. - `idle_ping_timeout` — RPINGs went unanswered. - `remote_close` — peer closed after handoff. - `local_close` — Envoy closed after handoff. - `explicit_close` — explicit close (e.g. shutdown). **Upstream network filter (`envoy.filters.upstream_network.reverse_tunnel_lifecycle`)** A new `ReverseTunnelUpstreamLifecycleFilter` (upstream read filter) is introduced to observe post-handoff connection events. On `onNewConnection()` it copies the tunnel's `ReverseTunnelLifecycleInfo` from the socket manager into the upstream connection's filter state. On `LocalClose` with `http2_ping_timeout`, it emits the `http2_keepalive_timeout` event through the extension's access loggers. It also provides the final close reason to the socket manager so the deferred `tunnel_closed` record carries the real reason rather than a generic `explicit_close`. **`UpstreamSocketManager` changes** - Tracks `fd_to_lifecycle_info_` map alongside existing fd maps. - Emits `tunnel_setup` on `addConnectionSocket()`. - Emits `socket_handoff` on `getConnectionSocket()`. - Emits `tunnel_closed` from `markSocketDead()`, with deferred close log support: when the upstream lifecycle filter is attached and no close reason is known yet, the close log is deferred until the filter reports the reason via `maybeEmitDeferredCloseLog()`. - Sets close reason on idle-phase failures: `idle_peer_close`, `idle_read_error`, `idle_ping_write_failure`, `idle_ping_timeout`. - Passes `tenant_id` through `handoffSocketToWorker()` and `addConnectionSocket()` so lifecycle info retains the original tenant. **`ReverseTunnelAcceptorExtension` changes** - Constructor moved from header to `.cc` to instantiate access loggers from config via `AccessLog::AccessLogFactory::fromProto()`. - Two new emit methods: - `emitSyntheticLifecycleLog()` — builds a temporary `StreamInfoImpl` from lifecycle metadata (used for idle-phase events and close events where no real connection StreamInfo exists). - `emitConnectionLifecycleLog()` — populates an existing connection's StreamInfo with lifecycle metadata (used for post-handoff events). - Both write dynamic metadata and filter state, then call all configured access loggers. **`ReverseTunnelFilter` change** - `processAcceptedConnection()` now passes the original (unscoped) node_id, cluster_id, and tenant_id to `addConnectionSocket()`. The socket manager derives tenant-scoped internal keys itself, keeping lifecycle metadata clean. **Docs** - New "Lifecycle access logs" section in `reverse_tunnel.rst` documenting config, events, metadata fields, and the upstream network filter. Risk Level: Low — additive only; no logs emitted unless `access_log` is configured. Testing: - `reverse_tunnel_upstream_lifecycle_test.cc` — unit tests for the upstream lifecycle filter: filter state propagation, keepalive timeout event emission, remote/local close reason forwarding, deferred close log behavior. - `upstream_socket_manager_test.cc` — lifecycle log tests: tunnel_setup on add, socket_handoff on get, tunnel_closed on markSocketDead with correct close reasons for each idle-phase failure mode. - `config_validation_test.cc` — validates the new access_log proto field parses. Docs Changes: Added lifecycle access logs section and upstream network filter usage to `docs/root/configuration/other_features/reverse_tunnel.rst`. Release Notes: N/A (reverse tunnel is not a public-facing feature) Platform Specific Features: N/A Signed-off-by: Krishna Sharma <[email protected]> Signed-off-by: Krishna Sharma <[email protected]> Signed-off-by: Jiawei Wu <[email protected]>
Emit structured lifecycle records for tunnel setup, handoff, close, and post-handoff HTTP/2 keepalive timeouts so reverse-tunnel behavior can be debugged from access logs without relying on codec changes. <!-- !!!ATTENTION!!! If you are fixing *any* crash or *any* potential security issue, *do not* open a pull request in this repo. Please report the issue via emailing [email protected] where the issue will be triaged appropriately. Thank you in advance for helping to keep Envoy secure. !!!ATTENTION!!! For an explanation of how to fill out the fields, please see the relevant section in [PULL_REQUESTS.md](https://github.com/envoyproxy/envoy/blob/main/PULL_REQUESTS.md) !!!ATTENTION!!! Please check the [use of generative AI policy](https://github.com/envoyproxy/envoy/blob/main/CONTRIBUTING.md?plain=1#L41). You may use generative AI only if you fully understand the code. You need to disclose this usage in the PR description to ensure transparency. --> Commit Message: reverse_tunnel: add lifecycle access logging Additional Description: Today, debugging reverse tunnel connection issues (silent drops, keepalive timeouts, unexpected closes) requires correlating codec-level debug logs across multiple threads and connections. This PR adds first-class access log support to the reverse tunnel upstream socket interface so that operators can observe the full tunnel lifecycle from structured, machine-parseable access logs. **Proto change (`UpstreamReverseConnectionSocketInterface`)** A new `repeated config.accesslog.v3.AccessLog access_log = 6` field is added to the bootstrap config. When configured, lifecycle events are emitted through the standard Envoy access log framework. No logs are emitted when the field is absent — fully backward compatible. **Lifecycle info struct (`ReverseTunnelLifecycleInfo`)** A new `reverse_tunnel_lifecycle_info.h` header defines: - `ReverseTunnelLifecycleInfo` — per-socket metadata carried through the tunnel lifetime: `node_id`, `cluster_id`, `tenant_id`, local/remote addresses, worker name, file descriptor, and state flags (`handed_off_to_upstream`, `upstream_lifecycle_filter_attached`, `socket_dead_notified`, `close_log_emitted`, `close_reason`). - Well-known string constants for all lifecycle events, socket states, handoff kinds, close reasons, filter-state keys, and the dynamic metadata namespace. **Lifecycle events emitted** Each access log record is written into the `envoy.reverse_tunnel.lifecycle` dynamic metadata namespace with these fields: | Field | Description | |----------------|---------------------------------------------------------------| | `event` | One of the event names below. | | `node_id` | Originating node identifier. | | `cluster_id` | Originating cluster identifier. | | `tenant_id` | Tenant identifier (empty when tenant isolation is off). | | `worker` | Envoy worker thread that owns the socket. | | `fd` | File descriptor number. | | `socket_state` | `idle`, `handed_off`, or `in_use`. | | `handoff_kind` | Present only on `socket_handoff`: `pool_to_upstream`. | | `close_reason` | Present only on `tunnel_closed` (see close reasons below). | The same node/cluster/tenant/worker/fd values are also written into connection filter state under `envoy.reverse_tunnel.*` keys so they can be referenced in `%FILTER_STATE(...)%` format strings. *Core lifecycle events:* - `tunnel_setup` — reverse tunnel accepted and cached. - `socket_handoff` — idle socket handed off to the upstream connection pool. - `tunnel_closed` — socket removed from tracking (final event for every tunnel). - `http2_keepalive_timeout` — upstream closed locally due to HTTP/2 PING timeout after handoff. *Idle-phase ping events (while socket is cached):* - `idle_ping_sent` / `idle_ping_ack` / `idle_ping_miss` / `idle_ping_timeout` *Post-handoff HTTP/2 keepalive events:* - `http2_keepalive_ping_sent` / `http2_keepalive_ping_ack` *Close reason values on `tunnel_closed`:* - `idle_peer_close` — peer closed while idle. - `idle_read_error` — read error on the idle socket. - `idle_ping_write_failure` — RPING write failed. - `idle_ping_timeout` — RPINGs went unanswered. - `remote_close` — peer closed after handoff. - `local_close` — Envoy closed after handoff. - `explicit_close` — explicit close (e.g. shutdown). **Upstream network filter (`envoy.filters.upstream_network.reverse_tunnel_lifecycle`)** A new `ReverseTunnelUpstreamLifecycleFilter` (upstream read filter) is introduced to observe post-handoff connection events. On `onNewConnection()` it copies the tunnel's `ReverseTunnelLifecycleInfo` from the socket manager into the upstream connection's filter state. On `LocalClose` with `http2_ping_timeout`, it emits the `http2_keepalive_timeout` event through the extension's access loggers. It also provides the final close reason to the socket manager so the deferred `tunnel_closed` record carries the real reason rather than a generic `explicit_close`. **`UpstreamSocketManager` changes** - Tracks `fd_to_lifecycle_info_` map alongside existing fd maps. - Emits `tunnel_setup` on `addConnectionSocket()`. - Emits `socket_handoff` on `getConnectionSocket()`. - Emits `tunnel_closed` from `markSocketDead()`, with deferred close log support: when the upstream lifecycle filter is attached and no close reason is known yet, the close log is deferred until the filter reports the reason via `maybeEmitDeferredCloseLog()`. - Sets close reason on idle-phase failures: `idle_peer_close`, `idle_read_error`, `idle_ping_write_failure`, `idle_ping_timeout`. - Passes `tenant_id` through `handoffSocketToWorker()` and `addConnectionSocket()` so lifecycle info retains the original tenant. **`ReverseTunnelAcceptorExtension` changes** - Constructor moved from header to `.cc` to instantiate access loggers from config via `AccessLog::AccessLogFactory::fromProto()`. - Two new emit methods: - `emitSyntheticLifecycleLog()` — builds a temporary `StreamInfoImpl` from lifecycle metadata (used for idle-phase events and close events where no real connection StreamInfo exists). - `emitConnectionLifecycleLog()` — populates an existing connection's StreamInfo with lifecycle metadata (used for post-handoff events). - Both write dynamic metadata and filter state, then call all configured access loggers. **`ReverseTunnelFilter` change** - `processAcceptedConnection()` now passes the original (unscoped) node_id, cluster_id, and tenant_id to `addConnectionSocket()`. The socket manager derives tenant-scoped internal keys itself, keeping lifecycle metadata clean. **Docs** - New "Lifecycle access logs" section in `reverse_tunnel.rst` documenting config, events, metadata fields, and the upstream network filter. Risk Level: Low — additive only; no logs emitted unless `access_log` is configured. Testing: - `reverse_tunnel_upstream_lifecycle_test.cc` — unit tests for the upstream lifecycle filter: filter state propagation, keepalive timeout event emission, remote/local close reason forwarding, deferred close log behavior. - `upstream_socket_manager_test.cc` — lifecycle log tests: tunnel_setup on add, socket_handoff on get, tunnel_closed on markSocketDead with correct close reasons for each idle-phase failure mode. - `config_validation_test.cc` — validates the new access_log proto field parses. Docs Changes: Added lifecycle access logs section and upstream network filter usage to `docs/root/configuration/other_features/reverse_tunnel.rst`. Release Notes: N/A (reverse tunnel is not a public-facing feature) Platform Specific Features: N/A Signed-off-by: Krishna Sharma <[email protected]> Signed-off-by: Krishna Sharma <[email protected]> Signed-off-by: Alireza <[email protected]>
`ReverseTunnelAcceptorExtension` had no destructor, so its members were destroyed in reverse declaration order: the reporter (and the rest of the extension's state) before `tls_slot_`. Destroying `tls_slot_` destroys each worker's `UpstreamSocketManager`, whose destructor marks its sockets dead and reports back through the extension, by then partly destroyed. Under GCC with optimization this segfaulted at every teardown of `ReverseTunnelFilterWithUpstreamTest`; at fastbuild it depends on how the freed memory is reused, so it shows up as a flake. Reset `tls_slot_` first in an explicit destructor, and clear the acceptor singleton's pointer to the extension so it does not outlive it. Backport note: written for this branch. `main` has the destructor's ordering since envoyproxy#44298 and the pointer clear since envoyproxy#48441, which do not apply here. Deflaked `//test/extensions/filters/network/reverse_tunnel:filter_unit_test` with GCC `-c opt` on envoy-ci-staging: 1000/1000 runs segfault without this, 1000/1000 pass with it. Signed-off-by: Ryan Northey <[email protected]>
`ReverseTunnelAcceptorExtension` had no destructor, so its members were destroyed in reverse declaration order: the reporter (and the rest of the extension's state) before `tls_slot_`. Destroying `tls_slot_` destroys each worker's `UpstreamSocketManager`, whose destructor marks its sockets dead and reports back through the extension, by then partly destroyed. Under GCC with optimization this segfaulted at every teardown of `ReverseTunnelFilterWithUpstreamTest`; at fastbuild it depends on how the freed memory is reused, so it shows up as a flake. Reset `tls_slot_` first in an explicit destructor, and clear the acceptor singleton's pointer to the extension so it does not outlive it. The reverse tunnel filter and reverse connection cluster tests replaced the acceptor before the extension built on it, and freed the TLS slot's registry while the extension still held the slot. As on `main` (envoyproxy#48441), they now detach the slot and destroy the extension first. Backport note: written for this branch. `main` has the destructor's ordering since envoyproxy#44298 and the pointer clear since envoyproxy#48441, which do not apply here. Deflaked `//test/extensions/filters/network/reverse_tunnel:filter_unit_test` with GCC `-c opt` on envoy-ci-staging: 1000/1000 runs segfault without this, 1000/1000 pass with it. Signed-off-by: Ryan Northey <[email protected]>
`ReverseTunnelAcceptorExtension` had no destructor, so its members were destroyed in reverse declaration order: the reporter (and the rest of the extension's state) before `tls_slot_`. Destroying `tls_slot_` destroys each worker's `UpstreamSocketManager`, whose destructor marks its sockets dead and reports back through the extension, by then partly destroyed. Under GCC with optimization this segfaulted at every teardown of `ReverseTunnelFilterWithUpstreamTest`; at fastbuild it depends on how the freed memory is reused, so it shows up as a flake. Reset `tls_slot_` first in an explicit destructor, and clear the acceptor singleton's pointer to the extension so it does not outlive it. The reverse tunnel filter and reverse connection cluster tests replaced the acceptor before the extension built on it, and freed the TLS slot's registry while the extension still held the slot. As on `main` (envoyproxy#48441), they now detach the slot and destroy the extension first. Backport note: written for this branch. `main` has the destructor's ordering since envoyproxy#44298 and the pointer clear since envoyproxy#48441, which do not apply here. Deflaked `//test/extensions/filters/network/reverse_tunnel:filter_unit_test` with GCC `-c opt` on envoy-ci-staging: 1000/1000 runs segfault without this, 1000/1000 pass with it. Signed-off-by: Ryan Northey <[email protected]>
`ReverseTunnelAcceptorExtension` had no destructor, so its members were destroyed in reverse declaration order: the reporter (and the rest of the extension's state) before `tls_slot_`. Destroying `tls_slot_` destroys each worker's `UpstreamSocketManager`, whose destructor marks its sockets dead and reports back through the extension, by then partly destroyed. Under GCC with optimization this segfaulted at every teardown of `ReverseTunnelFilterWithUpstreamTest`; at fastbuild it depends on how the freed memory is reused, so it shows up as a flake. Reset `tls_slot_` first in an explicit destructor, and clear the acceptor singleton's pointer to the extension so it does not outlive it. The reverse tunnel filter and reverse connection cluster tests replaced the acceptor before the extension built on it, and freed the TLS slot's registry while the extension still held the slot. As on `main` (envoyproxy#48441), they now detach the slot and destroy the extension first. Backport note: written for this branch. `main` has the destructor's ordering since envoyproxy#44298 and the pointer clear since envoyproxy#48441, which do not apply here. Deflaked `//test/extensions/filters/network/reverse_tunnel:filter_unit_test` with GCC `-c opt` on envoy-ci-staging: 1000/1000 runs segfault without this, 1000/1000 pass with it. Backport note (release/v1.37): with this branch's `onServerInitialized()`, and not the tenant isolation tests release/v1.38 has. Signed-off-by: Ryan Northey <[email protected]>
`ReverseTunnelAcceptorExtension` had no destructor, so its members were destroyed in reverse declaration order: the reporter (and the rest of the extension's state) before `tls_slot_`. Destroying `tls_slot_` destroys each worker's `UpstreamSocketManager`, whose destructor marks its sockets dead and reports back through the extension, by then partly destroyed. Under GCC with optimization this segfaulted at every teardown of `ReverseTunnelFilterWithUpstreamTest`; at fastbuild it depends on how the freed memory is reused, so it shows up as a flake. Reset `tls_slot_` first in an explicit destructor, and clear the acceptor singleton's pointer to the extension so it does not outlive it. The reverse tunnel filter and reverse connection cluster tests replaced the acceptor before the extension built on it, and freed the TLS slot's registry while the extension still held the slot. As on `main` (envoyproxy#48441), they now detach the slot and destroy the extension first. Backport note: written for this branch. `main` has the destructor's ordering since envoyproxy#44298 and the pointer clear since envoyproxy#48441, which do not apply here. Deflaked `//test/extensions/filters/network/reverse_tunnel:filter_unit_test` with GCC `-c opt` on envoy-ci-staging: 1000/1000 runs segfault without this, 1000/1000 pass with it. Backport note (release/v1.37): with this branch's `onServerInitialized()`, and not the tenant isolation tests release/v1.38 has. Signed-off-by: Ryan Northey <[email protected]>
`ReverseTunnelAcceptorExtension` had no destructor, so its members were destroyed in reverse declaration order: the reporter (and the rest of the extension's state) before `tls_slot_`. Destroying `tls_slot_` destroys each worker's `UpstreamSocketManager`, whose destructor marks its sockets dead and reports back through the extension, by then partly destroyed. Under GCC with optimization this segfaulted at every teardown of `ReverseTunnelFilterWithUpstreamTest`; at fastbuild it depends on how the freed memory is reused, so it shows up as a flake. Reset `tls_slot_` first in an explicit destructor, and clear the acceptor singleton's pointer to the extension so it does not outlive it. The reverse tunnel filter and reverse connection cluster tests replaced the acceptor before the extension built on it, and freed the TLS slot's registry while the extension still held the slot. As on `main` (envoyproxy#48441), they now detach the slot and destroy the extension first. Backport note: written for this branch. `main` has the destructor's ordering since envoyproxy#44298 and the pointer clear since envoyproxy#48441, which do not apply here. Deflaked `//test/extensions/filters/network/reverse_tunnel:filter_unit_test` with GCC `-c opt` on envoy-ci-staging: 1000/1000 runs segfault without this, 1000/1000 pass with it. Backport note (release/v1.37): with this branch's `onServerInitialized()`, and not the tenant isolation tests release/v1.38 has. Signed-off-by: Ryan Northey <[email protected]>
`ReverseTunnelAcceptorExtension` had no destructor, so its members were destroyed in reverse declaration order: the reporter (and the rest of the extension's state) before `tls_slot_`. Destroying `tls_slot_` destroys each worker's `UpstreamSocketManager`, whose destructor marks its sockets dead and reports back through the extension, by then partly destroyed. Under GCC with optimization this segfaulted at every teardown of `ReverseTunnelFilterWithUpstreamTest`; at fastbuild it depends on how the freed memory is reused, so it shows up as a flake. Reset `tls_slot_` first in an explicit destructor, and clear the acceptor singleton's pointer to the extension so it does not outlive it. The reverse tunnel filter and reverse connection cluster tests replaced the acceptor before the extension built on it, and freed the TLS slot's registry while the extension still held the slot. As on `main` (envoyproxy#48441), they now detach the slot and destroy the extension first. Backport note: written for this branch. `main` has the destructor's ordering since envoyproxy#44298 and the pointer clear since envoyproxy#48441, which do not apply here. Deflaked `//test/extensions/filters/network/reverse_tunnel:filter_unit_test` with GCC `-c opt` on envoy-ci-staging: 1000/1000 runs segfault without this, 1000/1000 pass with it. Backport note (release/v1.37): with this branch's `onServerInitialized()`, and not the tenant isolation tests release/v1.38 has. Signed-off-by: Ryan Northey <[email protected]>
`ReverseTunnelAcceptorExtension` had no destructor, so its members were destroyed in reverse declaration order: the reporter (and the rest of the extension's state) before `tls_slot_`. Destroying `tls_slot_` destroys each worker's `UpstreamSocketManager`, whose destructor marks its sockets dead and reports back through the extension, by then partly destroyed. Under GCC with optimization this segfaulted at every teardown of `ReverseTunnelFilterWithUpstreamTest`; at fastbuild it depends on how the freed memory is reused, so it shows up as a flake. Reset `tls_slot_` first in an explicit destructor, and clear the acceptor singleton's pointer to the extension so it does not outlive it. The reverse tunnel filter and reverse connection cluster tests replaced the acceptor before the extension built on it, and freed the TLS slot's registry while the extension still held the slot. As on `main` (envoyproxy#48441), they now detach the slot and destroy the extension first. Backport note: written for this branch. `main` has the destructor's ordering since envoyproxy#44298 and the pointer clear since envoyproxy#48441, which do not apply here. Deflaked `//test/extensions/filters/network/reverse_tunnel:filter_unit_test` with GCC `-c opt` on envoy-ci-staging: 1000/1000 runs segfault without this, 1000/1000 pass with it. Backport note (release/v1.37): with this branch's `onServerInitialized()`, and not the tenant isolation tests release/v1.38 has. Signed-off-by: Ryan Northey <[email protected]>
`ReverseTunnelAcceptorExtension` had no destructor, so its members were destroyed in reverse declaration order: the reporter (and the rest of the extension's state) before `tls_slot_`. Destroying `tls_slot_` destroys each worker's `UpstreamSocketManager`, whose destructor marks its sockets dead and reports back through the extension, by then partly destroyed. Under GCC with optimization this segfaulted at every teardown of `ReverseTunnelFilterWithUpstreamTest`; at fastbuild it depends on how the freed memory is reused, so it shows up as a flake. Reset `tls_slot_` first in an explicit destructor, and clear the acceptor singleton's pointer to the extension so it does not outlive it. The reverse tunnel filter and reverse connection cluster tests replaced the acceptor before the extension built on it, and freed the TLS slot's registry while the extension still held the slot. As on `main` (envoyproxy#48441), they now detach the slot and destroy the extension first. Backport note: written for this branch. `main` has the destructor's ordering since envoyproxy#44298 and the pointer clear since envoyproxy#48441, which do not apply here. Deflaked `//test/extensions/filters/network/reverse_tunnel:filter_unit_test` with GCC `-c opt` on envoy-ci-staging: 1000/1000 runs segfault without this, 1000/1000 pass with it. Backport note (release/v1.37): with this branch's `onServerInitialized()`, and not the tenant isolation tests release/v1.38 has. Signed-off-by: Ryan Northey <[email protected]>
`ReverseTunnelAcceptorExtension` had no destructor, so its members were destroyed in reverse declaration order: the reporter (and the rest of the extension's state) before `tls_slot_`. Destroying `tls_slot_` destroys each worker's `UpstreamSocketManager`, whose destructor marks its sockets dead and reports back through the extension, by then partly destroyed. Under GCC with optimization this segfaulted at every teardown of `ReverseTunnelFilterWithUpstreamTest`; at fastbuild it depends on how the freed memory is reused, so it shows up as a flake. Reset `tls_slot_` first in an explicit destructor, and clear the acceptor singleton's pointer to the extension so it does not outlive it. The reverse tunnel filter and reverse connection cluster tests replaced the acceptor before the extension built on it, and freed the TLS slot's registry while the extension still held the slot. As on `main` (envoyproxy#48441), they now detach the slot and destroy the extension first. Backport note: written for this branch. `main` has the destructor's ordering since envoyproxy#44298 and the pointer clear since envoyproxy#48441, which do not apply here. Deflaked `//test/extensions/filters/network/reverse_tunnel:filter_unit_test` with GCC `-c opt` on envoy-ci-staging: 1000/1000 runs segfault without this, 1000/1000 pass with it. Backport note (release/v1.37): with this branch's `onServerInitialized()`, and not the tenant isolation tests release/v1.38 has. Signed-off-by: Ryan Northey <[email protected]>
`ReverseTunnelAcceptorExtension` had no destructor, so its members were destroyed in reverse declaration order: the reporter (and the rest of the extension's state) before `tls_slot_`. Destroying `tls_slot_` destroys each worker's `UpstreamSocketManager`, whose destructor marks its sockets dead and reports back through the extension, by then partly destroyed. Under GCC with optimization this segfaulted at every teardown of `ReverseTunnelFilterWithUpstreamTest`; at fastbuild it depends on how the freed memory is reused, so it shows up as a flake. Reset `tls_slot_` first in an explicit destructor, and clear the acceptor singleton's pointer to the extension so it does not outlive it. The reverse tunnel filter and reverse connection cluster tests replaced the acceptor before the extension built on it, and freed the TLS slot's registry while the extension still held the slot. As on `main` (envoyproxy#48441), they now detach the slot and destroy the extension first. Backport note: written for this branch. `main` has the destructor's ordering since envoyproxy#44298 and the pointer clear since envoyproxy#48441, which do not apply here. Deflaked `//test/extensions/filters/network/reverse_tunnel:filter_unit_test` with GCC `-c opt` on envoy-ci-staging: 1000/1000 runs segfault without this, 1000/1000 pass with it. Signed-off-by: Ryan Northey <[email protected]>
`ReverseTunnelAcceptorExtension` had no destructor, so its members were destroyed in reverse declaration order: the reporter (and the rest of the extension's state) before `tls_slot_`. Destroying `tls_slot_` destroys each worker's `UpstreamSocketManager`, whose destructor marks its sockets dead and reports back through the extension, by then partly destroyed. Under GCC with optimization this segfaulted at every teardown of `ReverseTunnelFilterWithUpstreamTest`; at fastbuild it depends on how the freed memory is reused, so it shows up as a flake. Reset `tls_slot_` first in an explicit destructor, and clear the acceptor singleton's pointer to the extension so it does not outlive it. The reverse tunnel filter and reverse connection cluster tests replaced the acceptor before the extension built on it, and freed the TLS slot's registry while the extension still held the slot. As on `main` (envoyproxy#48441), they now detach the slot and destroy the extension first. Backport note: written for this branch. `main` has the destructor's ordering since envoyproxy#44298 and the pointer clear since envoyproxy#48441, which do not apply here. Deflaked `//test/extensions/filters/network/reverse_tunnel:filter_unit_test` with GCC `-c opt` on envoy-ci-staging: 1000/1000 runs segfault without this, 1000/1000 pass with it. Backport note (release/v1.37): with this branch's `onServerInitialized()`, and not the tenant isolation tests release/v1.38 has. Signed-off-by: Ryan Northey <[email protected]>
`ReverseTunnelAcceptorExtension` had no destructor, so its members were destroyed in reverse declaration order: the reporter (and the rest of the extension's state) before `tls_slot_`. Destroying `tls_slot_` destroys each worker's `UpstreamSocketManager`, whose destructor marks its sockets dead and reports back through the extension, by then partly destroyed. Under GCC with optimization this segfaulted at every teardown of `ReverseTunnelFilterWithUpstreamTest`; at fastbuild it depends on how the freed memory is reused, so it shows up as a flake. Reset `tls_slot_` first in an explicit destructor, and clear the acceptor singleton's pointer to the extension so it does not outlive it. The reverse tunnel filter and reverse connection cluster tests replaced the acceptor before the extension built on it, and freed the TLS slot's registry while the extension still held the slot. As on `main` (#48441), they now detach the slot and destroy the extension first. Backport note: written for this branch. `main` has the destructor's ordering since #44298 and the pointer clear since #48441, which do not apply here. Deflaked `//test/extensions/filters/network/reverse_tunnel:filter_unit_test` with GCC `-c opt` on envoy-ci-staging: 1000/1000 runs segfault without this, 1000/1000 pass with it. Signed-off-by: Ryan Northey <[email protected]>
`ReverseTunnelAcceptorExtension` had no destructor, so its members were destroyed in reverse declaration order: the reporter (and the rest of the extension's state) before `tls_slot_`. Destroying `tls_slot_` destroys each worker's `UpstreamSocketManager`, whose destructor marks its sockets dead and reports back through the extension, by then partly destroyed. Under GCC with optimization this segfaulted at every teardown of `ReverseTunnelFilterWithUpstreamTest`; at fastbuild it depends on how the freed memory is reused, so it shows up as a flake. Reset `tls_slot_` first in an explicit destructor, and clear the acceptor singleton's pointer to the extension so it does not outlive it. The reverse tunnel filter and reverse connection cluster tests replaced the acceptor before the extension built on it, and freed the TLS slot's registry while the extension still held the slot. As on `main` (envoyproxy#48441), they now detach the slot and destroy the extension first. Backport note: written for this branch. `main` has the destructor's ordering since envoyproxy#44298 and the pointer clear since envoyproxy#48441, which do not apply here. Deflaked `//test/extensions/filters/network/reverse_tunnel:filter_unit_test` with GCC `-c opt` on envoy-ci-staging: 1000/1000 runs segfault without this, 1000/1000 pass with it. Backport note (release/v1.37): with this branch's `onServerInitialized()`, and not the tenant isolation tests release/v1.38 has. Signed-off-by: Ryan Northey <[email protected]>
Emit structured lifecycle records for tunnel setup, handoff, close, and post-handoff HTTP/2 keepalive timeouts so reverse-tunnel behavior can be debugged from access logs without relying on codec changes.
Commit Message: reverse_tunnel: add lifecycle access logging
Additional Description:
Today, debugging reverse tunnel connection issues (silent drops, keepalive
timeouts, unexpected closes) requires correlating codec-level debug logs
across multiple threads and connections. This PR adds first-class access log
support to the reverse tunnel upstream socket interface so that operators can
observe the full tunnel lifecycle from structured, machine-parseable access
logs.
Proto change (
UpstreamReverseConnectionSocketInterface)A new
repeated config.accesslog.v3.AccessLog access_log = 6field is addedto the bootstrap config. When configured, lifecycle events are emitted through
the standard Envoy access log framework. No logs are emitted when the field is
absent — fully backward compatible.
Lifecycle info struct (
ReverseTunnelLifecycleInfo)A new
reverse_tunnel_lifecycle_info.hheader defines:ReverseTunnelLifecycleInfo— per-socket metadata carried through the tunnellifetime:
node_id,cluster_id,tenant_id, local/remote addresses,worker name, file descriptor, and state flags (
handed_off_to_upstream,upstream_lifecycle_filter_attached,socket_dead_notified,close_log_emitted,close_reason).kinds, close reasons, filter-state keys, and the dynamic metadata namespace.
Lifecycle events emitted
Each access log record is written into the
envoy.reverse_tunnel.lifecycledynamic metadata namespace with these fields:
eventnode_idcluster_idtenant_idworkerfdsocket_stateidle,handed_off, orin_use.handoff_kindsocket_handoff:pool_to_upstream.close_reasontunnel_closed(see close reasons below).The same node/cluster/tenant/worker/fd values are also written into connection
filter state under
envoy.reverse_tunnel.*keys so they can be referenced in%FILTER_STATE(...)%format strings.Core lifecycle events:
tunnel_setup— reverse tunnel accepted and cached.socket_handoff— idle socket handed off to the upstream connection pool.tunnel_closed— socket removed from tracking (final event for every tunnel).http2_keepalive_timeout— upstream closed locally due to HTTP/2 PING timeoutafter handoff.
Idle-phase ping events (while socket is cached):
idle_ping_sent/idle_ping_ack/idle_ping_miss/idle_ping_timeoutPost-handoff HTTP/2 keepalive events:
http2_keepalive_ping_sent/http2_keepalive_ping_ackClose reason values on
tunnel_closed:idle_peer_close— peer closed while idle.idle_read_error— read error on the idle socket.idle_ping_write_failure— RPING write failed.idle_ping_timeout— RPINGs went unanswered.remote_close— peer closed after handoff.local_close— Envoy closed after handoff.explicit_close— explicit close (e.g. shutdown).Upstream network filter (
envoy.filters.upstream_network.reverse_tunnel_lifecycle)A new
ReverseTunnelUpstreamLifecycleFilter(upstream read filter) isintroduced to observe post-handoff connection events. On
onNewConnection()itcopies the tunnel's
ReverseTunnelLifecycleInfofrom the socket manager intothe upstream connection's filter state. On
LocalClosewithhttp2_ping_timeout, it emits thehttp2_keepalive_timeoutevent through theextension's access loggers. It also provides the final close reason to the
socket manager so the deferred
tunnel_closedrecord carries the real reasonrather than a generic
explicit_close.UpstreamSocketManagerchangesfd_to_lifecycle_info_map alongside existing fd maps.tunnel_setuponaddConnectionSocket().socket_handoffongetConnectionSocket().tunnel_closedfrommarkSocketDead(), with deferred close logsupport: when the upstream lifecycle filter is attached and no close reason
is known yet, the close log is deferred until the filter reports the reason
via
maybeEmitDeferredCloseLog().idle_peer_close,idle_read_error,idle_ping_write_failure,idle_ping_timeout.tenant_idthroughhandoffSocketToWorker()andaddConnectionSocket()so lifecycle info retains the original tenant.ReverseTunnelAcceptorExtensionchanges.ccto instantiate access loggers fromconfig via
AccessLog::AccessLogFactory::fromProto().emitSyntheticLifecycleLog()— builds a temporaryStreamInfoImplfromlifecycle metadata (used for idle-phase events and close events where no
real connection StreamInfo exists).
emitConnectionLifecycleLog()— populates an existing connection'sStreamInfo with lifecycle metadata (used for post-handoff events).
access loggers.
ReverseTunnelFilterchangeprocessAcceptedConnection()now passes the original (unscoped) node_id,cluster_id, and tenant_id to
addConnectionSocket(). The socket managerderives tenant-scoped internal keys itself, keeping lifecycle metadata
clean.
Docs
reverse_tunnel.rstdocumenting config,events, metadata fields, and the upstream network filter.
Risk Level: Low — additive only; no logs emitted unless
access_logis configured.Testing:
reverse_tunnel_upstream_lifecycle_test.cc— unit tests for the upstreamlifecycle filter: filter state propagation, keepalive timeout event emission,
remote/local close reason forwarding, deferred close log behavior.
upstream_socket_manager_test.cc— lifecycle log tests: tunnel_setup on add,socket_handoff on get, tunnel_closed on markSocketDead with correct close
reasons for each idle-phase failure mode.
config_validation_test.cc— validates the new access_log proto field parses.Docs Changes: Added lifecycle access logs section and upstream network filter
usage to
docs/root/configuration/other_features/reverse_tunnel.rst.Release Notes: N/A (reverse tunnel is not a public-facing feature)
Platform Specific Features: N/A