Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request transform causes an out-of-memory panic #1122

Closed
ilijabojanovic opened this issue Sep 15, 2017 · 4 comments · Fixed by #1166
Closed

Request transform causes an out-of-memory panic #1122

ilijabojanovic opened this issue Sep 15, 2017 · 4 comments · Fixed by #1166
Assignees
Labels
Milestone

Comments

@ilijabojanovic
Copy link
Member

Branch: Master
rev: d83299a

Reproduction steps:

  1. Add api definition
  2. Enable request transform on endpoint
  3. Trigger get call to endpoint with request transform

Here is testing api definition:

{
    "id": "59ba8291b44d9901d3cd66bb",
    "name": "test3",
    "slug": "test3",
    "api_id": "c5635579fc1b4e3e56db777e03ff0e3f",
    "org_id": "59ba58daf1c5e702d237b293",
    "use_keyless": true,
    "use_oauth2": false,
    "use_openid": false,
    "openid_options": {
        "providers": [],
        "segregate_by_client": false
    },
    "oauth_meta": {
        "allowed_access_types": [],
        "allowed_authorize_types": [],
        "auth_login_redirect": ""
    },
    "auth": {
        "use_param": false,
        "param_name": "",
        "use_cookie": false,
        "cookie_name": "",
        "auth_header_name": ""
    },
    "use_basic_auth": false,
    "enable_jwt": false,
    "use_standard_auth": false,
    "enable_coprocess_auth": false,
    "jwt_signing_method": "",
    "jwt_source": "",
    "jwt_identity_base_field": "",
    "jwt_client_base_field": "",
    "jwt_policy_field_name": "",
    "notifications": {
        "shared_secret": "",
        "oauth_on_keychange_url": ""
    },
    "enable_signature_checking": false,
    "hmac_allowed_clock_skew": -1,
    "base_identity_provided_by": "",
    "definition": {
        "location": "header",
        "key": "x-api-version"
    },
    "version_data": {
        "not_versioned": true,
        "versions": {
            "Default": {
                "name": "Default",
                "expires": "",
                "paths": {
                    "ignored": [],
                    "white_list": [],
                    "black_list": []
                },
                "use_extended_paths": true,
                "extended_paths": {
                    "transform": [
                        {
                            "template_data": {
                                "input_type": "xml",
                                "template_mode": "blob",
                                "enable_session": false,
                                "template_source": "ewogICAge3tyYW5nZSAkeCwgJHMgOj0gLnNlcnZlcnMuc2VydmVyfX0gICAgInt7JHMuc2VydmVyTmFtZX19IjogInt7JHMuc2VydmVySVB9fSJ7e2lmIG5vdCAkeH19LHt7ZW5kfX0KICAgIHt7ZW5kfX0KICAgIH0="
                            },
                            "path": "/ip",
                            "method": "GET"
                        }
                    ]
                },
                "global_headers": {},
                "global_headers_remove": [],
                "global_size_limit": 0,
                "override_target": ""
            }
        }
    },
    "uptime_tests": {
        "check_list": [],
        "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_timeout": 60,
                "endpoint_returns_list": false
            },
            "recheck_wait": 0
        }
    },
    "proxy": {
        "preserve_host_header": false,
        "listen_path": "/test3/",
        "target_url": "http://httpbin.org/",
        "strip_listen_path": true,
        "enable_load_balancing": false,
        "target_list": [],
        "check_host_against_uptime_tests": false,
        "service_discovery": {
            "use_discovery_service": false,
            "query_endpoint": "",
            "use_nested_query": false,
            "parent_data_path": "",
            "data_path": "hostname",
            "port_data_path": "port",
            "target_path": "/api-slug",
            "use_target_list": false,
            "cache_timeout": 60,
            "endpoint_returns_list": false
        }
    },
    "disable_rate_limit": false,
    "disable_quota": false,
    "custom_middleware": {
        "pre": [],
        "post": [],
        "post_key_auth": [],
        "auth_check": {
            "name": "",
            "path": "",
            "require_session": false
        },
        "response": [],
        "driver": "",
        "id_extractor": {
            "extract_from": "",
            "extract_with": "",
            "extractor_config": {}
        }
    },
    "custom_middleware_bundle": "",
    "cache_options": {
        "cache_timeout": 60,
        "enable_cache": true,
        "cache_all_safe_requests": false,
        "cache_response_codes": [],
        "enable_upstream_cache_control": false
    },
    "session_lifetime": 0,
    "active": true,
    "auth_provider": {
        "name": "",
        "storage_engine": "",
        "meta": {}
    },
    "session_provider": {
        "name": "",
        "storage_engine": "",
        "meta": null
    },
    "event_handlers": {
        "events": {}
    },
    "enable_batch_request_support": false,
    "enable_ip_whitelisting": false,
    "allowed_ips": [],
    "dont_set_quota_on_create": false,
    "expire_analytics_after": 0,
    "response_processors": [],
    "CORS": {
        "enable": false,
        "allowed_origins": [],
        "allowed_methods": [],
        "allowed_headers": [],
        "exposed_headers": [],
        "allow_credentials": false,
        "max_age": 24,
        "options_passthrough": false,
        "debug": false
    },
    "domain": "",
    "do_not_track": false,
    "tags": [],
    "enable_context_vars": false,
    "config_data": {}
}

Trigger GET call to /ip endpoint

Gateway will crash without panic. In log i just have this:

tyk-gateway_1    | /develop/start/entrypoint.sh: line 22:   518 Killed                  ./tyk --conf=/develop/confs/tyk.conf --debug --httpprofile
compose_tyk-gateway_1 exited with code 137
@ilijabojanovic ilijabojanovic added this to the Release 2.4 milestone Sep 15, 2017
@mvdan mvdan changed the title Request transform causes memory leak Request transform causes an out-of-memory panic Sep 15, 2017
@mvdan
Copy link
Contributor

mvdan commented Sep 15, 2017

I wouldn't call this a leak. A leak is something that slowly fills up memory and never frees it. This crashes the gateway in mere seconds (at least on my laptop), as memory fills up incredibly fast.

@ilijabojanovic have you tried stable? what happens there?

@ilijabojanovic
Copy link
Member Author

@mvdan issue is not visible on current stable. When i trigger call to transformed endpoint, gateway starts to eat memory and crash when consumes all memory.

@mvdan
Copy link
Contributor

mvdan commented Sep 15, 2017

cool, thanks

@mvdan
Copy link
Contributor

mvdan commented Sep 29, 2017

This seems to be a bug in the mxj package. mxj.NewMapXmlReader takes forever and crashes the runtime, while mxj.NewMapXml (i.e. reading the whole body into memory first ourselves) just errors instantly.

buger pushed a commit that referenced this issue Sep 29, 2017
This was a crash in the mxj library concerning invalid input from a
reader, as it would not properly error and stop. We did not hit this
before in 2.3.x as we used a []byte, not an io.Reader.

The upstream issue is clbanning/mxj#38, fixed
back in February.

Add a regression test and bump the vendored version.

Fixes #1122.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants