Skip to content

Envoy internal listener's active connections are not released with TcpProxy case #38148

Closed

Description

@daphnesang

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

  1. 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

  2. send traffic:
    curl -vvv -x http://localhost:10000 https://example.com --http1.1

  3. 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

  1. added
    triage
    on Jan 22, 2025
  2. daphnesang commented on Jan 22, 2025

    @daphnesang
    Author
    No description provided.
  3. daphnesang commented on Jan 23, 2025

    @daphnesang
    Author

    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:

    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
                    max_downstream_connection_duration: 30s
                    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 }
    
  4. adisuissa commented on Jan 23, 2025

    @adisuissa
    Contributor

    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

  5. daphnesang commented on Jan 24, 2025

    @daphnesang
    Author

    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:

    1. the upstream connection closes but some data is still bening written to the internal listener's connections.
    2. The above case (1.) can happen when upstream sends some data and FIN without waiting for the envoy to ACK the data

    NOT working case log:

    [2025-01-23 00:55:02.144][29][debug][pool] [source/common/conn_pool/conn_pool_base.cc:463] invoking 0 idle callback(s) - is_draining_for_deletion_=false
    [2025-01-23 00:55:02.144][29][debug][connection] [source/common/network/connection_impl.cc:150] [Tags: "ConnectionId":"129"] closing data_to_write=31 type=0   
    [2025-01-23 00:55:02.144][29][trace][io] [source/extensions/io_socket/user_space/file_event_impl.cc:61] User space file event 0x72e3f55b080 set enabled events 2 and events 0 is active. Will not reschedule.
    [2025-01-23 00:55:02.144][29][trace][main] [source/common/event/dispatcher_impl.cc:127] clearing deferred deletion list (size=2)
    

    The working case log:

    2025-01-23 05:00:35.113][15][debug][pool] [source/common/conn_pool/conn_pool_base.cc:463] invoking 0 idle callback(s) - is_draining_for_deletion_=false
    [2025-01-23 05:00:35.113][15][debug][connection] [source/common/network/connection_impl.cc:150] [Tags: "ConnectionId":"11"] closing data_to_write=0 type=0
    [2025-01-23 05:00:35.113][15][debug][connection] [source/common/network/connection_impl.cc:276] [Tags: "ConnectionId":"11"] closing socket: 1
    [2025-01-23 05:00:35.113][15][trace][io] [source/extensions/io_socket/user_space/io_handle_impl.cc:80] socket 0x16217f6f8680 close after peer closed.
    [2025-01-23 05:00:35.113][15][trace][connection] [source/common/network/connection_impl.cc:469] [Tags: "ConnectionId":"11"] raising connection event 1
    [2025-01-23 05:00:35.113][15][trace][filter] [source/common/tcp_proxy/tcp_proxy.cc:813] [Tags: "ConnectionId":"11"] on downstream event 1, has upstream = false
    [2025-01-23 05:00:35.113][15][trace][conn_handler] [source/common/listener_manager/active_stream_listener_base.cc:126] [Tags: "ConnectionId":"11"] tcp connection on event 1
    [2025-01-23 05:00:35.113][15][debug][conn_handler] [source/common/listener_manager/active_stream_listener_base.cc:136] [Tags: "ConnectionId":"11"] adding to cleanup list
    [2025-01-23 05:00:35.113][15][trace][main] [source/common/event/dispatcher_impl.cc:233] item added to deferred deletion list (size=3)
    [2025-01-23 05:00:35.113][15][trace][main] [source/common/event/dispatcher_impl.cc:233] item added to deferred deletion list (size=4)
    closing data_to_write[2025-01-23 05:00:35.113][15][trace][main] [source/common/event/dispatcher_impl.cc:127] clearing deferred deletion list (size=4)
    

    cc @lambdai

  6. adisuissa commented on Jan 24, 2025

    @adisuissa
    Contributor

    I'm wondering about the "connection" to the internal listener (not related to the downstream/upstream being used).

  7. daphne-sang commented on Jan 24, 2025

    @daphne-sang

    @adisuissa: in this case, the flow path is ingress listener --> internal listener + TcpProxy (nomitm), no HTTP connection manager (HCM) involved.

  8. daphne-sang commented on Jan 27, 2025

    @daphne-sang

    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.

    envoy/source/common/tcp_proxy/tcp_proxy.cc):
    
    void Filter::initialize(Network::ReadFilterCallbacks& callbacks, bool set_connection_stats) {
      read_callbacks_ = &callbacks;
      ENVOY_CONN_LOG(debug, "new tcp proxy session", read_callbacks_->connection());
    
      read_callbacks_->connection().addConnectionCallbacks(downstream_callbacks_);
      //read_callbacks_->connection().enableHalfClose(true);
      read_callbacks_->connection().enableHalfClose(false);             // -----> disable HalfClose
    

    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.

                - 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
    

    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.

                  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 
    
  9. daphne-sang commented on Jan 28, 2025

    @daphne-sang

    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.

    +---
    + source/extensions/io_socket/user_space/file_event_impl.cc | 3 +++
    + source/extensions/io_socket/user_space/io_handle.h        | 5 +++++
    + source/extensions/io_socket/user_space/io_handle_impl.h   | 1 +
    + 3 files changed, 9 insertions(+)
    +
    +diff --git a/source/extensions/io_socket/user_space/file_event_impl.cc b/source/extensions/io_socket/user_space/file_event_impl.cc
    +index 32c0f0a638..42320c75fa 100644
    +--- a/source/extensions/io_socket/user_space/file_event_impl.cc
    ++++ b/source/extensions/io_socket/user_space/file_event_impl.cc
    +@@ -50,6 +50,9 @@ void FileEventImpl::setEnabled(uint32_t events) {
    +   if ((events & Event::FileReadyType::Closed) && io_source_.isPeerShutDownWrite()) {
    +     events_to_notify |= Event::FileReadyType::Closed;
    +   }
    ++  if (!io_source_.isPeerExist() && !(events & Event::FileReadyType::Read)) {
    ++    events_to_notify |= Event::FileReadyType::Closed;
    ++  }
    +   if (events_to_notify != 0) {
    +     activate(events_to_notify);
    +   } else {
    +diff --git a/source/extensions/io_socket/user_space/io_handle.h b/source/extensions/io_socket/user_space/io_handle.h
    +index 8266c9e0b4..7b94c8d69c 100644
    +--- a/source/extensions/io_socket/user_space/io_handle.h
    ++++ b/source/extensions/io_socket/user_space/io_handle.h
    +@@ -90,6 +90,11 @@ public:
    +    * @return shared state between peering user space IO handles.
    +    */
    +   virtual PassthroughStateSharedPtr passthroughState() PURE;
    ++
    ++   /**
    ++   * @return true if the peer exists
    ++   */
    ++  virtual bool isPeerExist() PURE;
    + };
    + } // namespace UserSpace
    + } // namespace IoSocket
    +diff --git a/source/extensions/io_socket/user_space/io_handle_impl.h b/source/extensions/io_socket/user_space/io_handle_impl.h
    +index e1ff27ae48..8562d16294 100644
    +--- a/source/extensions/io_socket/user_space/io_handle_impl.h
    ++++ b/source/extensions/io_socket/user_space/io_handle_impl.h
    +@@ -138,6 +138,7 @@ public:
    +   bool isReadable() const override {
    +     return isPeerShutDownWrite() || pending_received_data_.length() > 0;
    +   }
    ++  bool isPeerExist() override {return peer_handle_ ? true: false;}
    + 
    +   // Set the peer which will populate the owned pending_received_data.
    +   void setPeerHandle(UserSpace::IoHandle* writable_peer) {
    +-- 
    +2.39.1
    +
     done
    
  10. alyssawilk commented on Jan 28, 2025

    @alyssawilk
    Contributor

    This would probably be something for @kyessenov to look into but unfortunately he's out for some time yet :-/

  11. github-actions commented on Mar 6, 2025

    @github-actions

    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.

  12. 5 remaining items

  13. self-assigned this
    on Nov 17, 2025
  14. removed
    stale
    on Nov 17, 2025
  15. daphnesang commented on Nov 20, 2025

    @daphnesang
    Author

    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.

  16. kyessenov commented on Dec 10, 2025

    @kyessenov
    Contributor

    Sorry, I don't have time to root cause this issue at the moment.

  17. github-actions commented on Jan 10, 2026

    @github-actions

    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.

  18. added
    stale
    on Jan 10, 2026
  19. daphnesang commented on Jan 10, 2026

    @daphnesang
    Author

    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!

  20. removed
    stale
    on Jan 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions