SSE streams are not being closed properly

We have a spring boot application with a tomcat webserver. When using tyk in front and there is a high load of streams expecially when client does not wait for response and keeps on spamming, the connection is being kept open on tomcat side and all sse streams stop working. (other non sse streams work)
We could not replicate the issue when testing directly without tyk.

Tyk logs show a lot of these erros:

 level=error msg="http: proxy error: context canceled"

File max set to following:

fs.file-max=10000000

— Version —

Release version: 5.6.1
Built by: goreleaser
Build date: 2024-10-18T11:54:46Z
Commit: 4c71f007d0a7c0588648a026e295e6e47314bdb5
Go version: go1.22.8
OS/Arch: linux/amd64

—Tyk and API Configs—

tyk.conf

{
  "log_level": "debug",
  "listen_address": "",
  "proxy_close_connections": false,
  "close_connections": false,
  "listen_port": 444,
  "control_api_hostname": "",
  "secret": "",
  "template_path": "/opt/tyk-gateway/templates",
  "use_db_app_configs": false,
  "app_path": "/opt/tyk-gateway/apps",
  "middleware_path": "/opt/tyk-gateway/middleware",
  "disable_ports_whitelist": true,
  "storage": {
    "type": "redis",
    "host": "localhost",
    "port": 6379,
    "username": "",
    "password": "",
    "database": 0,
    "optimisation_max_idle": 100,
    "optimisation_max_active": 0
  },
  "enable_analytics": true,
  "analytics_config": {
    "type": "",
    "ignored_ips": [],
"enable_geo_ip": true,
"enable_detailed_recording": true,
"normalise_urls": {
"enabled": true
}

  },
  "dns_cache": {
    "enabled": false,
    "ttl": 3600,
    "check_interval": 60
  },
  "allow_master_keys": false,
  "policies": {
    "policy_source": "file"
  },
  "enable_jsvm": true,
  "http_server_options":{
    "enable_websockets": false,
    "read_timeout": 0,
    "write_timeout": 0,
    "enable_http2": true,
    "flush_interval": 1,
    "use_ssl": true,
    "certificates": []
  },
  "proxy_enable_http2": true,
  "hash_keys": true,
  "hash_key_function": "murmur64",
  "suppress_redis_signal_reload": false,
  "force_global_session_lifetime": false,
  "global_session_lifetime": 0,
  "max_idle_connections_per_host": 0,
  "close_idle_connections": false,
  "enable_custom_domains": true,
  "proxy_default_timeout": 25

}
{
  "name": "trader-backend-tech",
  "slug": "",
  "listen_port": 443,
  "protocol": "https",
  "enable_proxy_protocol": false,
  "api_id": "dHJhZGVyL3RyYWRlcg",
  "org_id": "",
  "use_keyless": true,
  "use_oauth2": false,
  "external_oauth": {
    "enabled": false,
    "providers": null
  },
  "use_openid": false,
  "openid_options": {
    "providers": null,
    "segregate_by_client": false
  },
  "oauth_meta": {
    "allowed_access_types": null,
    "allowed_authorize_types": null,
    "auth_login_redirect": ""
  },
  "auth": {
    "name": "",
    "use_param": false,
    "param_name": "",
    "use_cookie": false,
    "cookie_name": "",
    "disable_header": false,
    "auth_header_name": "",
    "use_certificate": false,
    "validate_signature": false,
    "signature": {
      "algorithm": "",
      "header": "",
      "use_param": false,
      "param_name": "",
      "secret": "",
      "allowed_clock_skew": 0,
      "error_code": 0,
      "error_message": ""
    }
  },
  "auth_configs": null,
  "use_basic_auth": false,
  "basic_auth": {
    "disable_caching": false,
    "cache_ttl": 0,
    "extract_from_body": false,
    "body_user_regexp": "",
    "body_password_regexp": ""
  },
  "use_mutual_tls_auth": false,
  "client_certificates": null,
  "upstream_certificates": null,
  "pinned_public_keys": null,
  "enable_jwt": false,
  "use_standard_auth": false,
  "use_go_plugin_auth": false,
  "enable_coprocess_auth": false,
  "custom_plugin_auth_enabled": false,
  "jwt_signing_method": "",
  "jwt_source": "",
  "jwt_identity_base_field": "",
  "jwt_client_base_field": "",
  "jwt_policy_field_name": "",
  "jwt_default_policies": null,
  "jwt_issued_at_validation_skew": 0,
  "jwt_expires_at_validation_skew": 0,
  "jwt_not_before_validation_skew": 0,
  "jwt_skip_kid": false,
  "scopes": {
    "jwt": {},
    "oidc": {}
  },
  "idp_client_id_mapping_disabled": false,
  "jwt_scope_to_policy_mapping": null,
  "jwt_scope_claim_name": "",
  "notifications": {
    "shared_secret": "",
    "oauth_on_keychange_url": ""
  },
  "enable_signature_checking": false,
  "hmac_allowed_clock_skew": 0,
  "hmac_allowed_algorithms": null,
  "request_signing": {
    "is_enabled": false,
    "secret": "",
    "key_id": "",
    "algorithm": "",
    "header_list": null,
    "certificate_id": "",
    "signature_header": ""
  },
  "base_identity_provided_by": "",
  "definition": {
    "enabled": false,
    "name": "",
    "default": "",
    "location": "",
    "key": "",
    "strip_path": false,
    "strip_versioning_data": false,
    "url_versioning_pattern": "",
    "fallback_to_default": false,
    "versions": null
  },
  "version_data": {
    "not_versioned": true,
    "default_version": "Default",
    "versions": {
      "Default": {
        "name": "Default",
        "expires": "",
        "paths": {
          "ignored": null,
          "white_list": null,
          "black_list": null
        },
        "use_extended_paths": false,
        "extended_paths": {
          "persist_graphql": null,
          "rate_limit": null
        },
        "global_headers": null,
        "global_headers_remove": null,
        "global_headers_disabled": false,
        "global_response_headers": null,
        "global_response_headers_remove": null,
        "global_response_headers_disabled": false,
        "ignore_endpoint_case": false,
        "global_size_limit": 0,
        "override_target": ""
      }
    }
  },
  "uptime_tests": {
    "check_list": null,
    "config": {
      "expire_utime_after": 0,
      "service_discovery": {
        "use_discovery_service": false,
        "query_endpoint": "",
        "use_nested_query": false,
        "parent_data_path": "",
        "data_path": "",
        "port_data_path": "",
        "target_path": "",
        "use_target_list": false,
        "cache_disabled": false,
        "cache_timeout": 0,
        "endpoint_returns_list": false
      },
      "recheck_wait": 0
    }
  },
  "proxy": {
    "preserve_host_header": true,
    "listen_path": "/",
    "target_url": "http://a739f0846e7e042259b29267b7445e23-54d68eee4a683dea.elb.eu-central-1.amazonaws.com",
    "disable_strip_slash": false,
    "strip_listen_path": false,
    "enable_load_balancing": false,
    "target_list": null,
    "check_host_against_uptime_tests": false,
    "service_discovery": {
      "use_discovery_service": false,
      "query_endpoint": "",
      "use_nested_query": false,
      "parent_data_path": "",
      "data_path": "",
      "port_data_path": "",
      "target_path": "",
      "use_target_list": false,
      "cache_disabled": false,
      "cache_timeout": 0,
      "endpoint_returns_list": false
    },
    "transport": {
      "ssl_insecure_skip_verify": false,
      "ssl_ciphers": null,
      "ssl_min_version": 0,
      "ssl_max_version": 0,
      "ssl_force_common_name_check": false,
      "proxy_url": ""
    }
  },
  "disable_rate_limit": false,
  "disable_quota": false,
  "custom_middleware": {
    "pre": [],
    "post": null,
    "post_key_auth": null,
    "auth_check": {
      "disabled": false,
      "name": "",
      "path": "",
      "require_session": false,
      "raw_body_only": false
    },
    "response": null,
    "driver": "goplugin",
    "id_extractor": {
      "disabled": false,
      "extract_from": "",
      "extract_with": "",
      "extractor_config": {}
    }
  },
  "custom_middleware_bundle": "",
  "custom_middleware_bundle_disabled": false,
  "cache_options": {
    "cache_timeout": 0,
    "enable_cache": false,
    "cache_all_safe_requests": false,
    "cache_response_codes": null,
    "enable_upstream_cache_control": false,
    "cache_control_ttl_header": "",
    "cache_by_headers": null
  },
  "session_lifetime": 0,
  "active": true,
  "internal": false,
  "auth_provider": {
    "name": "",
    "storage_engine": "",
    "meta": null
  },
  "session_provider": {
    "name": "",
    "storage_engine": "",
    "meta": null
  },
  "event_handlers": {
    "events": null
  },
  "enable_batch_request_support": false,
  "enable_ip_whitelisting": false,
  "allowed_ips": null,
  "enable_ip_blacklisting": false,
  "blacklisted_ips": null,
  "dont_set_quota_on_create": false,
  "expire_analytics_after": 0,
  "response_processors": null,
  "CORS": {
    "enable": false,
    "allowed_origins": null,
    "allowed_methods": null,
    "allowed_headers": null,
    "exposed_headers": null,
    "allow_credentials": false,
    "max_age": 0,
    "options_passthrough": false,
    "debug": false
  },
  "domain": "",
  "certificates": null,
  "do_not_track": false,
  "enable_context_vars": true,
  "config_data": null,
  "config_data_disabled": false,
  "tag_headers": null,
  "global_rate_limit": {
    "disabled": false,
    "rate": 0,
    "per": 0
  },
  "strip_auth_data": false,
  "enable_detailed_recording": false,
  "graphql": {
    "enabled": false,
    "execution_mode": "",
    "version": "",
    "schema": "",
    "type_field_configurations": null,
    "playground": {
      "enabled": false,
      "path": ""
    },
    "engine": {
      "field_configs": null,
      "data_sources": null,
      "global_headers": null
    },
    "proxy": {
      "features": {
        "use_immutable_headers": false
      },
      "auth_headers": null,
      "request_headers": null,
      "use_response_extensions": {
        "on_error_forwarding": false
      },
      "request_headers_rewrite": null
    },
    "subgraph": {
      "sdl": ""
    },
    "supergraph": {
      "subgraphs": null,
      "merged_sdl": "",
      "global_headers": null,
      "disable_query_batching": false
    },
    "introspection": {
      "disabled": false
    }
  },
  "analytics_plugin": {},
  "tags": null,
  "detailed_tracing": false```

@gabriel_xuereb Hello and welcome to the community :partying_face:

http: proxy error: context canceled error indicates that the upstream connections are being closed unexpectedly. More info can be found in our docs page.

Looking at your config, I suspect this may be the issue. The source code sets the value to 120 if zero. So depending on the long running operation you may have, the downstream connection might have just timed out.

Our docs recommends setting the read and write timeout values to something very high