Repository navigation
Description
If you are reporting any crash or any potential security issue, do not
open an issue in this repo. Please report the issue via emailing
[email protected] where the issue will be triaged appropriately.
Title: Envoy internal listener's active connections are not released with TcpProxy case
Description:
running envoy:v1.33-latest image via docker, active connections created by internal listener (using TcpProxy) are not released
-
start envoy:v1.33-latest
docker run -d --name envoy -p 10000:10000 -p 9901:9901 -v $(pwd)/envoy.yaml:/etc/envoy/envoy.yaml:ro envoyproxy/envoy:v1.33-latest -l trace -c /etc/envoy/envoy.yaml -
send traffic:
curl -vvv -x http://localhost:10000 https://example.com --http1.1 -
The internal listener's active connections were NOT released nor cleaned up; the connections created by the internal listener were held indefinitely.
C02CCPDLMD6M ~/Desktop/PA_Project/myEnvoy date
Wed Jan 22 14:30:53 PST 2025
C02CCPDLMD6M ~/Desktop/PA_Project/myEnvoy curl -s http://localhost:9901/stats | grep cx_active | grep -vw 0
http.admin.downstream_cx_active: 1
listener.admin.downstream_cx_active: 1
listener.admin.main_thread.downstream_cx_active: 1
listener.envoy_internal_internal_listener_https.downstream_cx_active: 8
listener.envoy_internal_internal_listener_https.worker_1.downstream_cx_active: 1
listener.envoy_internal_internal_listener_https.worker_10.downstream_cx_active: 2
listener.envoy_internal_internal_listener_https.worker_3.downstream_cx_active: 2
listener.envoy_internal_internal_listener_https.worker_5.downstream_cx_active: 1
listener.envoy_internal_internal_listener_https.worker_7.downstream_cx_active: 1
listener.envoy_internal_internal_listener_https.worker_8.downstream_cx_active: 1
C02CCPDLMD6M ~/Desktop/PA_Project/myEnvoy curl -s http://localhost:9901/stats | grep cx_active | grep -vw 0
http.admin.downstream_cx_active: 1
listener.admin.downstream_cx_active: 1
listener.admin.main_thread.downstream_cx_active: 1
listener.envoy_internal_internal_listener_https.downstream_cx_active: 9
listener.envoy_internal_internal_listener_https.worker_1.downstream_cx_active: 1
listener.envoy_internal_internal_listener_https.worker_10.downstream_cx_active: 2
listener.envoy_internal_internal_listener_https.worker_2.downstream_cx_active: 1
listener.envoy_internal_internal_listener_https.worker_3.downstream_cx_active: 2
listener.envoy_internal_internal_listener_https.worker_5.downstream_cx_active: 1
listener.envoy_internal_internal_listener_https.worker_7.downstream_cx_active: 1
listener.envoy_internal_internal_listener_https.worker_8.downstream_cx_active: 1
C02CCPDLMD6M ~/Desktop/PA_Project/myEnvoy date
Wed Jan 22 14:58:57 PST 2025
Repro steps:
docker pull envoyproxy/envoy:v1.33-latest
run standalone Envoy v1.33 with internal listener enabled using TcpProxy
Note: The Envoy_collect tool
gathers a tarball with debug logs, config and the following admin
endpoints: /stats, /clusters and /server_info. Please note if there are
privacy concerns, sanitize the data prior to sharing the tarball/pasting.
Admin and Stats Output:
Include the admin output for the following endpoints: /stats,
/clusters, /routes, /server_info. For more information, refer to the
admin endpoint documentation.
Note: If there are privacy concerns, sanitize the data prior to
sharing.
Config:
envoy.yaml file
node:
id: test-id
cluster: test-cluster
bootstrap_extensions:
- name: envoy.bootstrap.internal_listener
typed_config:
"@type": type.googleapis.com/envoy.extensions.bootstrap.internal_listener.v3.InternalListener
static_resources:
listeners:
# Ingress Listener for HTTP and HTTPS
- name: ingress_listener
address:
socket_address: { address: 0.0.0.0, port_value: 10000 }
filter_chains:
- filters:
- name: envoy.filters.network.http_connection_manager
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
stat_prefix: ingress_http
codec_type: AUTO
route_config:
name: ingress_to_internal_route
virtual_hosts:
- name: internal_virtual_host
domains: ["*"]
routes:
- match: { connect_matcher: {} }
route:
cluster: internal_cluster_https
upgrade_configs:
- upgrade_type: CONNECT
connect_config: {}
- match: { prefix: "/" }
route:
cluster: internal_cluster_http
http_filters:
- name: envoy.filters.http.router
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
access_log:
- name: envoy.access_loggers.file
typed_config:
"@type": type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
path: "/tmp/envoy_access.log"
# Internal Listener for HTTP traffic
- name: internal_listener_http
internal_listener: {}
filter_chains:
- transport_socket:
name: envoy.transport_sockets.raw_buffer # http://
typed_config:
"@type": type.googleapis.com/envoy.extensions.transport_sockets.raw_buffer.v3.RawBuffer
transport_socket_connect_timeout: 0s
filters:
- name: envoy.filters.network.http_connection_manager
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
stat_prefix: internal_http
codec_type: AUTO
common_http_protocol_options:
idle_timeout: 15s
stream_idle_timeout: 15s
route_config:
name: internal_to_dynamic_route
virtual_hosts:
- name: dynamic_virtual_host
domains: ["*"]
routes:
- match: { prefix: "/" }
route:
cluster: dynamic_forward_proxy
http_filters:
- name: envoy.filters.http.dynamic_forward_proxy
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.dynamic_forward_proxy.v3.FilterConfig
dns_cache_config:
name: dynamic_forward_proxy_cache
dns_lookup_family: V4_ONLY
- name: envoy.filters.http.router
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
# Internal Listener for HTTPS traffic
- name: internal_listener_https
internal_listener: {}
listener_filters:
- name: "envoy.filters.listener.tls_inspector"
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.listener.tls_inspector.v3.TlsInspector
filter_chains:
- filters:
- name: envoy.filters.network.sni_dynamic_forward_proxy
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.sni_dynamic_forward_proxy.v3.FilterConfig
port_value: 443
dns_cache_config:
name: dynamic_forward_proxy_cache
dns_lookup_family: V4_ONLY
- name: envoy.filters.network.tcp_proxy
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.tcp_proxy.v3.TcpProxy
stat_prefix: internal_https
cluster: dynamic_forward_proxy
idle_timeout: 15s
access_log:
- name: envoy.access_loggers.file
typed_config:
"@type": type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
path: "/tmp/envoy_access.log"
clusters:
# Internal Cluster for HTTP traffic
- name: internal_cluster_http
connect_timeout: 15s
type: STATIC
lb_policy: ROUND_ROBIN
load_assignment:
cluster_name: internal_cluster_http
endpoints:
- lb_endpoints:
- endpoint:
address:
envoy_internal_address: { server_listener_name: internal_listener_http }
# Internal Cluster for HTTPS traffic
- name: internal_cluster_https
connect_timeout: 15s
type: STATIC
lb_policy: ROUND_ROBIN
load_assignment:
cluster_name: internal_cluster_https
endpoints:
- lb_endpoints:
- endpoint:
address:
envoy_internal_address: { server_listener_name: internal_listener_https }
# Dynamic Forward Proxy Cluster
- name: dynamic_forward_proxy
connect_timeout: 15s
lb_policy: CLUSTER_PROVIDED
cluster_type:
name: envoy.clusters.dynamic_forward_proxy
typed_config:
"@type": type.googleapis.com/envoy.extensions.clusters.dynamic_forward_proxy.v3.ClusterConfig
dns_cache_config:
name: dynamic_forward_proxy_cache
dns_lookup_family: V4_ONLY
transport_socket:
name: envoy.transport_sockets.raw_buffer
typed_config:
"@type": type.googleapis.com/envoy.extensions.transport_sockets.raw_buffer.v3.RawBuffer
admin:
access_log_path: "/tmp/admin_access.log"
address:
socket_address: { address: 0.0.0.0, port_value: 9901 }
Logs:
Include the access logs and the Envoy logs.
Envoy logs: attached file envoy_service.log
Envoy access logs:
docker exec -it envoy more /tmp/envoy_access.log:
[2025-01-22T22:20:48.464Z] "CONNECT - HTTP/1.1" 200 DC 578 7336 2873 - "-" "curl/8.7.1" "9e89c290-68d7-40d4-b18f-31fe2ba53cd9" "example.com:443" "envoy://internal_listener_https/"
[2025-01-22T22:20:54.394Z] "CONNECT - HTTP/1.1" 200 DC 578 7337 127 - "-" "curl/8.7.1" "b1759241-37f5-4f46-a998-844320ef050a" "example.com:443" "envoy://internal_listener_https/"
[2025-01-22T22:20:57.574Z] "CONNECT - HTTP/1.1" 200 DC 578 7338 123 - "-" "curl/8.7.1" "f32d9bce-691d-4127-978e-3968fe67c9f9" "example.com:443" "envoy://internal_listener_https/"
[2025-01-22T22:21:00.746Z] "CONNECT - HTTP/1.1" 200 DC 578 7336 133 - "-" "curl/8.7.1" "8b73e76b-a6f9-434a-891c-780efc3e363f" "example.com:443" "envoy://internal_listener_https/"
[2025-01-22T22:21:03.923Z] "CONNECT - HTTP/1.1" 200 DC 578 7338 85 - "-" "curl/8.7.1" "eb4457d4-c44b-431f-9b1d-8f9139c87570" "example.com:443" "envoy://internal_listener_https/"
[2025-01-22T22:21:07.044Z] "CONNECT - HTTP/1.1" 200 DC 578 7336 65 - "-" "curl/8.7.1" "63250ee4-069d-4e6d-a406-509c81428179" "example.com:443" "envoy://internal_listener_https/"
[2025-01-22T22:21:10.172Z] "CONNECT - HTTP/1.1" 200 DC 578 7336 1698 - "-" "curl/8.7.1" "a2d48e28-3177-4c23-9080-d3b6d89335bd" "example.com:443" "envoy://internal_listener_https/"
[2025-01-22T22:21:14.906Z] "CONNECT - HTTP/1.1" 200 DC 578 7337 208 - "-" "curl/8.7.1" "43a8a725-a397-4591-9824-ec76e71d6872" "example.com:443" "envoy://internal_listener_https/"
[2025-01-22T22:51:40.798Z] "CONNECT - HTTP/1.1" 200 DC 578 7337 128 - "-" "curl/8.7.1" "08f1f9fa-b104-4806-8d3b-50ab4744d42c" "example.com:443" "envoy://internal_listener_https/"
Note: If there are privacy concerns, sanitize the data prior to
sharing.
Call Stack:
If the Envoy binary is crashing, a call stack is required.
Please refer to the Bazel Stack trace documentation.
Activity
daphnesang commentedon Jan 22, 2025
daphnesang commentedon Jan 23, 2025
Additional note:
If adding max_downstream_connection_duration: 30s config under TcpProxy for internal_listener_https (see below), downstream_cx_active is cleared for internal_listener_https. see attached envoy log file envoyv1-33_workinglog.txt
Complete envoy.yaml config with max_downstream_connection_duration:
adisuissa commentedon Jan 23, 2025
I wonder if this behavior (the connections are kept open) is because H/2 is used to connect to the internal-listener, which keeps the connection open for reuse.
cc @alyssawilk
daphnesang commentedon Jan 24, 2025
Hi, @adisuissa, @alyssawilk
we are running http/1.1:
curl -vvv -x http://localhost:10000/ https://example.com/ --http1.1
This "not closing internal listener connections" case occurs when:
NOT working case log:
The working case log:
cc @lambdai
adisuissa commentedon Jan 24, 2025
I'm wondering about the "connection" to the internal listener (not related to the downstream/upstream being used).
daphne-sang commentedon Jan 24, 2025
@adisuissa: in this case, the flow path is ingress listener --> internal listener + TcpProxy (nomitm), no HTTP connection manager (HCM) involved.
daphne-sang commentedon Jan 27, 2025
Hi, @adisuissa, @alyssawilk, @lambdai:
Did some more testing, and here are the findings:
1. By disabling TcpProxy HalfClose, the issue is NOT there, the internal listener's connection is properly closed/released when TcpProxy HalfClose is disabled.
2. The issue seems related to TcpProxy's HalfClose handling, found an old issue #2067
Is the issue #2067 resolved?
3. Why idle_timeout configured under TcpProxy doesn't work in this case with HalfClosed enabled?
It seems the internal listeners rely on some inactivity timer to trigger the cleanup for the internal listener's connection (delayed close cases) w/ HalfClosed enabled? We have TcpProxy' idle_timeout configured, but idle_timeout under TcpProxy does not trigger "Close" event for the internal listener.
4. With internal listener + HCM (with stream_idle_timeout configured), it works -- upon stream_idle_timeout is reached, the internal listener's connection is closed and released.
daphne-sang commentedon Jan 28, 2025
Hi, @adisuissa, @alyssawilk, @lambdai:
Made the following change which has fixed the internal listener leak for TcpProxy w/ Half-Close case:
-- For Half-Closed TcpProxy connection, close it if the peer has already been destroyed.
Do you see any issue/side effect with this change? Thanks.
alyssawilk commentedon Jan 28, 2025
This would probably be something for @kyessenov to look into but unfortunately he's out for some time yet :-/
github-actions commentedon Mar 6, 2025
This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in the next 7 days unless it is tagged "help wanted" or "no stalebot" or other activity occurs. Thank you for your contributions.
5 remaining items
daphnesang commentedon Nov 20, 2025
Hi, @kyessenov:
Could you help provide some insight into why the internal listeners are not being released in v1.33? What is the proper way to clean up the internal listener resources?
The code diff I attached above is more of a short-term patch, and it feels like there should be a better mechanism to track and release internal listeners when the connection closes.
Also, has this issue already been fixed in the latest baseline?
Thanks.
kyessenov commentedon Dec 10, 2025
Sorry, I don't have time to root cause this issue at the moment.
github-actions commentedon Jan 10, 2026
This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in the next 7 days unless it is tagged "help wanted" or "no stalebot" or other activity occurs. Thank you for your contributions.
daphnesang commentedon Jan 10, 2026
Hi maintainers — this issue was automatically marked as stale.
Would it be possible to add a tag "help wanted" or "no stalebot" so the issue will not be automatically closed?
We're still waiting for some help to root-cause & solved the issue. Thanks!
userspace socket: treat a closed peer handle as writable (envoyproxy#…
userspace socket: treat a closed peer handle as writable (envoyproxy#…
userspace socket: treat a closed peer handle as writable (envoyproxy#…
userspace socket: treat a closed peer handle as writable (envoyproxy#…
userspace socket: treat a closed peer handle as writable (envoyproxy#…