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

Logs for 502 errors are always indicating GET, even if POST was used #4751

Closed
aspyct opened this issue Jun 25, 2019 · 1 comment · Fixed by #5073
Closed

Logs for 502 errors are always indicating GET, even if POST was used #4751

aspyct opened this issue Jun 25, 2019 · 1 comment · Fixed by #5073

Comments

@aspyct
Copy link

aspyct commented Jun 25, 2019

Summary

When an upstream server returns no data, kong correctly replies with a 502 error "An invalid response was received from the upstream server". That first part is correct.

However, in the logs (for example with tcp-log and udp-log), the request always shows up as a GET request, even if a POST was sent.

Note that it seems to happen ONLY when no byte is sent back by the upstream. The method is correct with a response of 6 bytes (haven't tested with less, but I suspect 1 byte is enough).

Impact

Mild, mostly. We did waste a few hours looking at our code with disbelief, but production still works.

Steps To Reproduce

Clone this repository and follow the steps in the README: https://github.com/aspyct/kong502
You'll need docker and docker-compose.

Additional Details & Logs

  • Kong version:
Seen from 1.1.1 to 1.2.0. Didn't test other versions
  • Kong debug-level startup logs ($ kong start --vv)
kong_1           | 2019/06/25 13:37:59 [verbose] Kong: 1.2.0
kong_1           | 2019/06/25 13:37:59 [debug] ngx_lua: 10013
kong_1           | 2019/06/25 13:37:59 [debug] nginx: 1013006
kong_1           | 2019/06/25 13:37:59 [debug] Lua: LuaJIT 2.1.0-beta3
kong_1           | 2019/06/25 13:37:59 [verbose] no config file found at /etc/kong/kong.conf
kong_1           | 2019/06/25 13:37:59 [verbose] no config file found at /etc/kong.conf
kong_1           | 2019/06/25 13:37:59 [verbose] no config file, skip loading
kong_1           | 2019/06/25 13:37:59 [debug] reading environment variables
kong_1           | 2019/06/25 13:37:59 [debug] KONG_DECLARATIVE_CONFIG ENV found with "/config/kong-config.yml"
kong_1           | 2019/06/25 13:37:59 [debug] KONG_DATABASE ENV found with "off"
kong_1           | 2019/06/25 13:37:59 [debug] KONG_NGINX_DAEMON ENV found with "off"
kong_1           | 2019/06/25 13:37:59 [debug] admin_access_log = "logs/admin_access.log"
kong_1           | 2019/06/25 13:37:59 [debug] admin_error_log = "logs/error.log"
kong_1           | 2019/06/25 13:37:59 [debug] admin_listen = {"127.0.0.1:8001","127.0.0.1:8444 ssl"}
kong_1           | 2019/06/25 13:37:59 [debug] anonymous_reports = true
kong_1           | 2019/06/25 13:37:59 [debug] cassandra_consistency = "ONE"
kong_1           | 2019/06/25 13:37:59 [debug] cassandra_contact_points = {"127.0.0.1"}
kong_1           | 2019/06/25 13:37:59 [debug] cassandra_data_centers = {"dc1:2","dc2:3"}
kong_1           | 2019/06/25 13:37:59 [debug] cassandra_keyspace = "kong"
kong_1           | 2019/06/25 13:37:59 [debug] cassandra_lb_policy = "RequestRoundRobin"
kong_1           | 2019/06/25 13:37:59 [debug] cassandra_port = 9042
kong_1           | 2019/06/25 13:37:59 [debug] cassandra_repl_factor = 1
kong_1           | 2019/06/25 13:37:59 [debug] cassandra_repl_strategy = "SimpleStrategy"
kong_1           | 2019/06/25 13:37:59 [debug] cassandra_schema_consensus_timeout = 10000
kong_1           | 2019/06/25 13:37:59 [debug] cassandra_ssl = false
kong_1           | 2019/06/25 13:37:59 [debug] cassandra_ssl_verify = false
kong_1           | 2019/06/25 13:37:59 [debug] cassandra_timeout = 5000
kong_1           | 2019/06/25 13:37:59 [debug] cassandra_username = "kong"
kong_1           | 2019/06/25 13:37:59 [debug] client_body_buffer_size = "8k"
kong_1           | 2019/06/25 13:37:59 [debug] client_max_body_size = "0"
kong_1           | 2019/06/25 13:37:59 [debug] client_ssl = false
kong_1           | 2019/06/25 13:37:59 [debug] database = "off"
kong_1           | 2019/06/25 13:37:59 [debug] db_cache_ttl = 0
kong_1           | 2019/06/25 13:37:59 [debug] db_cache_warmup_entities = {"services","plugins"}
kong_1           | 2019/06/25 13:37:59 [debug] db_resurrect_ttl = 30
kong_1           | 2019/06/25 13:37:59 [debug] db_update_frequency = 5
kong_1           | 2019/06/25 13:37:59 [debug] db_update_propagation = 0
kong_1           | 2019/06/25 13:37:59 [debug] declarative_config = "/config/kong-config.yml"
kong_1           | 2019/06/25 13:37:59 [debug] dns_error_ttl = 1
kong_1           | 2019/06/25 13:37:59 [debug] dns_hostsfile = "/etc/hosts"
kong_1           | 2019/06/25 13:37:59 [debug] dns_no_sync = false
kong_1           | 2019/06/25 13:37:59 [debug] dns_not_found_ttl = 30
kong_1           | 2019/06/25 13:37:59 [debug] dns_order = {"LAST","SRV","A","CNAME"}
kong_1           | 2019/06/25 13:37:59 [debug] dns_resolver = {}
kong_1           | 2019/06/25 13:37:59 [debug] dns_stale_ttl = 4
kong_1           | 2019/06/25 13:37:59 [debug] error_default_type = "text/plain"
kong_1           | 2019/06/25 13:37:59 [debug] headers = {"server_tokens","latency_tokens"}
kong_1           | 2019/06/25 13:37:59 [debug] log_level = "notice"
kong_1           | 2019/06/25 13:37:59 [debug] lua_package_cpath = ""
kong_1           | 2019/06/25 13:37:59 [debug] lua_package_path = "./?.lua;./?/init.lua;"
kong_1           | 2019/06/25 13:37:59 [debug] lua_socket_pool_size = 30
kong_1           | 2019/06/25 13:37:59 [debug] lua_ssl_verify_depth = 1
kong_1           | 2019/06/25 13:37:59 [debug] mem_cache_size = "128m"
kong_1           | 2019/06/25 13:37:59 [debug] nginx_admin_directives = {}
kong_1           | 2019/06/25 13:37:59 [debug] nginx_daemon = "off"
kong_1           | 2019/06/25 13:37:59 [debug] nginx_http_directives = {}
kong_1           | 2019/06/25 13:37:59 [debug] nginx_optimizations = true
kong_1           | 2019/06/25 13:37:59 [debug] nginx_proxy_directives = {}
kong_1           | 2019/06/25 13:37:59 [debug] nginx_sproxy_directives = {}
kong_1           | 2019/06/25 13:37:59 [debug] nginx_stream_directives = {}
kong_1           | 2019/06/25 13:37:59 [debug] nginx_user = "nobody nobody"
kong_1           | 2019/06/25 13:37:59 [debug] nginx_worker_processes = "auto"
kong_1           | 2019/06/25 13:37:59 [debug] origins = {}
kong_1           | 2019/06/25 13:37:59 [debug] pg_database = "kong"
kong_1           | 2019/06/25 13:37:59 [debug] pg_host = "127.0.0.1"
kong_1           | 2019/06/25 13:37:59 [debug] pg_max_concurrent_queries = 0
kong_1           | 2019/06/25 13:37:59 [debug] pg_port = 5432
kong_1           | 2019/06/25 13:37:59 [debug] pg_semaphore_timeout = 60000
kong_1           | 2019/06/25 13:37:59 [debug] pg_ssl = false
kong_1           | 2019/06/25 13:37:59 [debug] pg_ssl_verify = false
kong_1           | 2019/06/25 13:37:59 [debug] pg_timeout = 5000
kong_1           | 2019/06/25 13:37:59 [debug] pg_user = "kong"
kong_1           | 2019/06/25 13:37:59 [debug] plugins = {"bundled"}
kong_1           | 2019/06/25 13:37:59 [debug] prefix = "/usr/local/kong/"
kong_1           | 2019/06/25 13:37:59 [debug] proxy_access_log = "logs/access.log"
kong_1           | 2019/06/25 13:37:59 [debug] proxy_error_log = "logs/error.log"
kong_1           | 2019/06/25 13:37:59 [debug] proxy_listen = {"0.0.0.0:8000","0.0.0.0:8443 ssl"}
kong_1           | 2019/06/25 13:37:59 [debug] real_ip_header = "X-Real-IP"
kong_1           | 2019/06/25 13:37:59 [debug] real_ip_recursive = "off"
kong_1           | 2019/06/25 13:37:59 [debug] router_consistency = "strict"
kong_1           | 2019/06/25 13:37:59 [debug] ssl_cipher_suite = "modern"
kong_1           | 2019/06/25 13:37:59 [debug] ssl_ciphers = "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256"
kong_1           | 2019/06/25 13:37:59 [debug] stream_listen = {"off"}
kong_1           | 2019/06/25 13:37:59 [debug] trusted_ips = {}
kong_1           | 2019/06/25 13:37:59 [debug] upstream_keepalive = 60
kong_1           | 2019/06/25 13:37:59 [verbose] prefix in use: /usr/local/kong
kong_1           | 2019/06/25 13:37:59 [debug] loading subsystems migrations...
kong_1           | 2019/06/25 13:37:59 [verbose] retrieving cache schema state...
kong_1           | 2019/06/25 13:37:59 [verbose] schema state retrieved
kong_1           | 2019/06/25 13:37:59 [verbose] preparing nginx prefix directory at /usr/local/kong
kong_1           | 2019/06/25 13:37:59 [verbose] SSL enabled, no custom certificate set: using default certificate
kong_1           | 2019/06/25 13:37:59 [verbose] generating default SSL certificate and key
kong_1           | 2019/06/25 13:37:59 [verbose] Admin SSL enabled, no custom certificate set: using default certificate
kong_1           | 2019/06/25 13:37:59 [verbose] generating admin SSL certificate and key
kong_1           | 2019/06/25 13:37:59 [debug] searching for OpenResty 'nginx' executable
kong_1           | 2019/06/25 13:37:59 [debug] /usr/local/openresty/nginx/sbin/nginx -v: 'nginx version: openresty/1.13.6.2'
kong_1           | 2019/06/25 13:37:59 [debug] found OpenResty 'nginx' executable at /usr/local/openresty/nginx/sbin/nginx
kong_1           | 2019/06/25 13:37:59 [debug] testing nginx configuration: KONG_NGINX_CONF_CHECK=true /usr/local/openresty/nginx/sbin/nginx -t -p /usr/local/kong -c nginx.conf
kong_1           | 2019/06/25 13:37:59 [debug] searching for OpenResty 'nginx' executable
kong_1           | 2019/06/25 13:37:59 [debug] /usr/local/openresty/nginx/sbin/nginx -v: 'nginx version: openresty/1.13.6.2'
  • Kong error logs (<KONG_PREFIX>/logs/error.log)
2019/06/25 13:37:59 [notice] 23#0: using the "epoll" event method
2019/06/25 13:37:59 [notice] 23#0: openresty/1.13.6.2
2019/06/25 13:37:59 [notice] 23#0: built by gcc 8.3.0 (Alpine 8.3.0) 
2019/06/25 13:37:59 [notice] 23#0: OS: Linux 4.9.125-linuxkit
2019/06/25 13:37:59 [notice] 23#0: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2019/06/25 13:37:59 [notice] 23#0: start worker processes
2019/06/25 13:37:59 [notice] 23#0: start worker process 31
2019/06/25 13:37:59 [notice] 23#0: start worker process 32
2019/06/25 13:37:59 [notice] 31#0: *1 [kong] init.lua:240 declarative config loaded from /config/kong-config.yml, context: init_worker_by_lua*
2019/06/25 13:37:59 [warn] 31#0: *1 [lua] mesh.lua:86: init(): no cluster_ca in declarative configuration: cannot use node in mesh mode, context: init_worker_by_lua*
2019/06/25 13:47:35 [error] 31#0: *3442 upstream prematurely closed connection while reading response header from upstream, client: 172.23.0.1, server: kong, request: "POST /nothing HTTP/1.1", upstream: "http://172.23.0.4:8000/", host: "localhost:8000"
{
    "plugins": {
        "enabled_in_cluster": [
            "udp-log"
        ],
        "available_on_server": {
            "correlation-id": true,
            "pre-function": true,
            "cors": true,
            "ldap-auth": true,
            "loggly": true,
            "hmac-auth": true,
            "zipkin": true,
            "request-size-limiting": true,
            "azure-functions": true,
            "request-transformer": true,
            "oauth2": true,
            "response-transformer": true,
            "ip-restriction": true,
            "statsd": true,
            "jwt": true,
            "proxy-cache": true,
            "basic-auth": true,
            "key-auth": true,
            "http-log": true,
            "datadog": true,
            "tcp-log": true,
            "post-function": true,
            "prometheus": true,
            "acl": true,
            "kubernetes-sidecar-injector": true,
            "syslog": true,
            "file-log": true,
            "udp-log": true,
            "response-ratelimiting": true,
            "aws-lambda": true,
            "bot-detection": true,
            "rate-limiting": true,
            "request-termination": true
        }
    },
    "tagline": "Welcome to kong",
    "configuration": {
        "error_default_type": "text\/plain",
        "admin_listen": [
            "127.0.0.1:8001",
            "127.0.0.1:8444 ssl"
        ],
        "proxy_access_log": "logs\/access.log",
        "trusted_ips": {},
        "prefix": "\/usr\/local\/kong",
        "loaded_plugins": {
            "correlation-id": true,
            "pre-function": true,
            "cors": true,
            "rate-limiting": true,
            "loggly": true,
            "hmac-auth": true,
            "zipkin": true,
            "bot-detection": true,
            "azure-functions": true,
            "request-transformer": true,
            "oauth2": true,
            "response-transformer": true,
            "syslog": true,
            "statsd": true,
            "jwt": true,
            "proxy-cache": true,
            "basic-auth": true,
            "key-auth": true,
            "http-log": true,
            "datadog": true,
            "tcp-log": true,
            "post-function": true,
            "ldap-auth": true,
            "acl": true,
            "kubernetes-sidecar-injector": true,
            "ip-restriction": true,
            "file-log": true,
            "udp-log": true,
            "response-ratelimiting": true,
            "aws-lambda": true,
            "prometheus": true,
            "request-size-limiting": true,
            "request-termination": true
        },
        "cassandra_username": "kong",
        "ssl_cert_key": "\/usr\/local\/kong\/ssl\/kong-default.key",
        "admin_ssl_cert_key": "\/usr\/local\/kong\/ssl\/admin-kong-default.key",
        "dns_resolver": {},
        "pg_user": "kong",
        "mem_cache_size": "128m",
        "cassandra_data_centers": [
            "dc1:2",
            "dc2:3"
        ],
        "nginx_admin_directives": {},
        "nginx_http_directives": [
            {
                "value": "prometheus_metrics 5m",
                "name": "lua_shared_dict"
            }
        ],
        "pg_host": "127.0.0.1",
        "nginx_acc_logs": "\/usr\/local\/kong\/logs\/access.log",
        "pg_semaphore_timeout": 60000,
        "proxy_listen": [
            "0.0.0.0:8000",
            "0.0.0.0:8443 ssl"
        ],
        "declarative_config": "\/config\/kong-config.yml",
        "client_ssl_cert_default": "\/usr\/local\/kong\/ssl\/kong-default.crt",
        "cassandra_ssl": false,
        "dns_no_sync": false,
        "db_update_propagation": 0,
        "stream_listen": [
            "off"
        ],
        "nginx_err_logs": "\/usr\/local\/kong\/logs\/error.log",
        "cassandra_port": 9042,
        "dns_order": [
            "LAST",
            "SRV",
            "A",
            "CNAME"
        ],
        "dns_error_ttl": 1,
        "headers": [
            "server_tokens",
            "latency_tokens"
        ],
        "cassandra_lb_policy": "RequestRoundRobin",
        "nginx_optimizations": true,
        "origins": {},
        "database": "off",
        "pg_database": "kong",
        "nginx_worker_processes": "auto",
        "lua_package_cpath": "",
        "admin_acc_logs": "\/usr\/local\/kong\/logs\/admin_access.log",
        "admin_ssl_cert": "\/usr\/local\/kong\/ssl\/admin-kong-default.crt",
        "db_update_frequency": 5,
        "lua_package_path": ".\/?.lua;.\/?\/init.lua;",
        "nginx_pid": "\/usr\/local\/kong\/pids\/nginx.pid",
        "upstream_keepalive": 60,
        "lua_socket_pool_size": 30,
        "nginx_conf": "\/usr\/local\/kong\/nginx.conf",
        "dns_stale_ttl": 4,
        "router_consistency": "strict",
        "admin_access_log": "logs\/admin_access.log",
        "admin_ssl_cert_default": "\/usr\/local\/kong\/ssl\/admin-kong-default.crt",
        "nginx_kong_stream_conf": "\/usr\/local\/kong\/nginx-kong-stream.conf",
        "proxy_listeners": [
            {
                "transparent": false,
                "ssl": false,
                "ip": "0.0.0.0",
                "proxy_protocol": false,
                "port": 8000,
                "http2": false,
                "listener": "0.0.0.0:8000"
            },
            {
                "transparent": false,
                "ssl": true,
                "ip": "0.0.0.0",
                "proxy_protocol": false,
                "port": 8443,
                "http2": false,
                "listener": "0.0.0.0:8443 ssl"
            }
        ],
        "proxy_ssl_enabled": true,
        "client_ssl": false,
        "db_cache_warmup_entities": [
            "services",
            "plugins"
        ],
        "enabled_headers": {
            "latency_tokens": true,
            "X-Kong-Proxy-Latency": true,
            "Via": true,
            "server_tokens": true,
            "Server": true,
            "X-Kong-Upstream-Latency": true,
            "X-Kong-Upstream-Status": false
        },
        "stream_listeners": {},
        "plugins": [
            "bundled"
        ],
        "db_resurrect_ttl": 30,
        "ssl_ciphers": "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256",
        "cassandra_consistency": "ONE",
        "client_max_body_size": "0",
        "admin_error_log": "logs\/error.log",
        "pg_ssl_verify": false,
        "dns_not_found_ttl": 30,
        "pg_ssl": false,
        "nginx_proxy_directives": {},
        "kong_env": "\/usr\/local\/kong\/.kong_env",
        "cassandra_repl_strategy": "SimpleStrategy",
        "ssl_cipher_suite": "modern",
        "proxy_error_log": "logs\/error.log",
        "log_level": "notice",
        "pg_timeout": 60000,
        "nginx_kong_conf": "\/usr\/local\/kong\/nginx-kong.conf",
        "real_ip_header": "X-Real-IP",
        "dns_hostsfile": "\/etc\/hosts",
        "admin_listeners": [
            {
                "transparent": false,
                "ssl": false,
                "ip": "127.0.0.1",
                "proxy_protocol": false,
                "port": 8001,
                "http2": false,
                "listener": "127.0.0.1:8001"
            },
            {
                "transparent": false,
                "ssl": true,
                "ip": "127.0.0.1",
                "proxy_protocol": false,
                "port": 8444,
                "http2": false,
                "listener": "127.0.0.1:8444 ssl"
            }
        ],
        "pg_max_concurrent_queries": 0,
        "ssl_cert": "\/usr\/local\/kong\/ssl\/kong-default.crt",
        "cassandra_timeout": 60000,
        "admin_ssl_cert_key_default": "\/usr\/local\/kong\/ssl\/admin-kong-default.key",
        "cassandra_ssl_verify": false,
        "cassandra_schema_consensus_timeout": 60000,
        "cassandra_contact_points": [
            "127.0.0.1"
        ],
        "real_ip_recursive": "off",
        "cassandra_repl_factor": 1,
        "client_ssl_cert_key_default": "\/usr\/local\/kong\/ssl\/kong-default.key",
        "nginx_daemon": "off",
        "anonymous_reports": true,
        "nginx_sproxy_directives": {},
        "nginx_stream_directives": {},
        "pg_port": 5432,
        "admin_ssl_enabled": true,
        "client_body_buffer_size": "8k",
        "ssl_preread_enabled": true,
        "ssl_cert_csr_default": "\/usr\/local\/kong\/ssl\/kong-default.csr",
        "lua_ssl_verify_depth": 1,
        "cassandra_keyspace": "kong",
        "ssl_cert_default": "\/usr\/local\/kong\/ssl\/kong-default.crt",
        "ssl_cert_key_default": "\/usr\/local\/kong\/ssl\/kong-default.key",
        "db_cache_ttl": 0
    },
    "version": "1.2.0",
    "node_id": "78152aff-94ce-4106-a6f4-0eb0bc2610f5",
    "lua_version": "LuaJIT 2.1.0-beta3",
    "prng_seeds": {
        "pid: 31": 113224819215,
        "pid: 23": 601951812101,
        "pid: 32": 991042399176
    },
    "timers": {
        "pending": 5,
        "running": 0
    },
    "hostname": "f356717e9dae"
}
  • Operating system:
Official docker image.
@thibaultcha
Copy link
Member

Hi,

Thank you for the report. This is a known issue, which comes from an Nginx limitation. This has already been reported in #4025, which also proposes an Nginx patch that will be shipped with an upcoming release of Kong (and OpenResty, eventually).

Closing this in the meantime so we can keep the conversation focused on #4025.

Best,

thibaultcha added a commit that referenced this issue Sep 26, 2019
…errors

This commit fixes the outstanding caveat of using logging plugins to log
NGINX-produced errors. The caveat - described in e709c95 - causes some
request properties (i.e. method and uri args) to be incorrectly logged.

Since e709c95, Kong executes plugins on NGINX-produced errors. However,
as described in the mentioned commit's message, a caveat with the
approach (note: the sanest one) is that the request method is overridden
by the `error_page` directive during the internal redirect (and the uri
args do not survive the redirect either).

This commit chooses to rely on the PDK to fix this limitation, and
manually parses the request headers when necessary (and possible).

Fix #4025
Fix #4751
hishamhm pushed a commit that referenced this issue Sep 27, 2019
…errors

This commit fixes the outstanding caveat of using logging plugins to log
NGINX-produced errors. The caveat - described in e709c95 - causes some
request properties (i.e. method and uri args) to be incorrectly logged.

Since e709c95, Kong executes plugins on NGINX-produced errors. However,
as described in the mentioned commit's message, a caveat with the
approach (note: the sanest one) is that the request method is overridden
by the `error_page` directive during the internal redirect (and the uri
args do not survive the redirect either).

This commit chooses to rely on the PDK to fix this limitation, and
manually parses the request headers when necessary (and possible).

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

Successfully merging a pull request may close this issue.

2 participants