linkerd2 icon indicating copy to clipboard operation
linkerd2 copied to clipboard

invalid HTTP method parsed

Open tarvip opened this issue 5 years ago • 20 comments

Bug Report

What is the issue?

After upgrading Linkerd to stable-2.10.1 some proxies (not all) are logging following lines:

{"timestamp":"[   517.977900s]","level":"INFO","fields":{"message":"Connection closed","error":"invalid HTTP method parsed"},"target":"linkerd_app_core::serve","spans":[{"name":"daemon"},{"listen.addr":"0.0.0.0:4191","name":"admin"},{"client.addr":"10.0.5.162:51408","name":"accept"}],"threadId":"ThreadId(2)"}

About 2 messages per second.

How can it be reproduced?

Not sure how to reproduce, in my case at least 2 clusters were affected by this, haven't upgraded prod cluster.

Logs, error output, etc

I enabled debug logs as well then the output is following:

{"timestamp":"[   517.977546s]","level":"DEBUG","fields":{"message":"Peeked bytes from TCP stream","sz":289},"target":"linkerd_tls::server","spans":[{"name":"daemon"},{"listen.addr":"0.0.0.0:4191","name":"admin"},{"client.addr":"10.0.5.162:51408","name":"accept"}],"threadId":"ThreadId(2)"}
{"timestamp":"[   517.977605s]","level":"DEBUG","fields":{"message":"Identified foreign SNI","sni":"..."},"target":"linkerd_tls::server","spans":[{"name":"daemon"},{"listen.addr":"0.0.0.0:4191","name":"admin"},{"client.addr":"10.0.5.162:51408","name":"accept"}],"threadId":"ThreadId(2)"}
{"timestamp":"[   517.977643s]","level":"DEBUG","fields":{"message":"DetectResult","protocol":"None","elapsed":"7.9µs"},"target":"linkerd_detect","spans":[{"name":"daemon"},{"listen.addr":"0.0.0.0:4191","name":"admin"},{"client.addr":"10.0.5.162:51408","name":"accept"}],"threadId":"ThreadId(2)"}
{"timestamp":"[   517.977663s]","level":"DEBUG","fields":{"message":"Failed to parse HTTP request; handling as HTTP/1"},"target":"linkerd_app::admin","spans":[{"name":"daemon"},{"listen.addr":"0.0.0.0:4191","name":"admin"},{"client.addr":"10.0.5.162:51408","name":"accept"}],"threadId":"ThreadId(2)"}
{"timestamp":"[   517.977687s]","level":"DEBUG","fields":{"message":"Creating HTTP service","version":"Http1"},"target":"linkerd_proxy_http::server","spans":[{"name":"daemon"},{"listen.addr":"0.0.0.0:4191","name":"admin"},{"client.addr":"10.0.5.162:51408","name":"accept"}],"threadId":"ThreadId(2)"}
{"timestamp":"[   517.977717s]","level":"DEBUG","fields":{"message":"Handling as HTTP","version":"Http1"},"target":"linkerd_proxy_http::server","spans":[{"name":"daemon"},{"listen.addr":"0.0.0.0:4191","name":"admin"},{"client.addr":"10.0.5.162:51408","name":"accept"}],"threadId":"ThreadId(2)"}
{"timestamp":"[   517.977831s]","level":"DEBUG","fields":{"message":"The client is shutting down the connection","res":"Err(hyper::Error(Parse(Method)))"},"target":"linkerd_proxy_http::server","spans":[{"name":"daemon"},{"listen.addr":"0.0.0.0:4191","name":"admin"},{"client.addr":"10.0.5.162:51408","name":"accept"}],"threadId":"ThreadId(2)"}
{"timestamp":"[   517.977900s]","level":"INFO","fields":{"message":"Connection closed","error":"invalid HTTP method parsed"},"target":"linkerd_app_core::serve","spans":[{"name":"daemon"},{"listen.addr":"0.0.0.0:4191","name":"admin"},{"client.addr":"10.0.5.162:51408","name":"accept"}],"threadId":"ThreadId(2)"}

IP 10.0.5.162 belongs to linkerd-viz.prometheus.

linkerd check output

kubernetes-api
--------------
√ can initialize the client
√ can query the Kubernetes API

kubernetes-version
------------------
√ is running the minimum Kubernetes API version
√ is running the minimum kubectl version

linkerd-existence
-----------------
√ 'linkerd-config' config map exists
√ heartbeat ServiceAccount exist
√ control plane replica sets are ready
√ no unschedulable pods
√ controller pod is running

linkerd-config
--------------
√ control plane Namespace exists
√ control plane ClusterRoles exist
√ control plane ClusterRoleBindings exist
√ control plane ServiceAccounts exist
√ control plane CustomResourceDefinitions exist
√ control plane MutatingWebhookConfigurations exist
√ control plane ValidatingWebhookConfigurations exist
√ control plane PodSecurityPolicies exist

linkerd-identity
----------------
√ certificate config is valid
√ trust anchors are using supported crypto algorithm
√ trust anchors are within their validity period
√ trust anchors are valid for at least 60 days
√ issuer cert is using supported crypto algorithm
√ issuer cert is within its validity period
√ issuer cert is valid for at least 60 days
√ issuer cert is issued by the trust anchor

linkerd-webhooks-and-apisvc-tls
-------------------------------
√ proxy-injector webhook has valid cert
√ proxy-injector cert is valid for at least 60 days
√ sp-validator webhook has valid cert
√ sp-validator cert is valid for at least 60 days

linkerd-api
-----------
√ control plane pods are ready
√ can initialize the client
√ can query the control plane API

linkerd-version
---------------
√ can determine the latest version
√ cli is up-to-date

control-plane-version
---------------------
√ control plane is up-to-date
√ control plane and cli versions match

Status check results are √

Linkerd extensions checks
=========================

linkerd-viz
-----------
√ linkerd-viz Namespace exists
√ linkerd-viz ClusterRoles exist
√ linkerd-viz ClusterRoleBindings exist
√ tap API server has valid cert
√ tap API server cert is valid for at least 60 days
√ tap API service is running
√ linkerd-viz pods are injected
√ viz extension pods are running
√ prometheus is installed and configured correctly
√ can initialize the client
√ viz extension self-check

Status check results are √

Environment

  • Kubernetes Version: v1.18.9-eks-d1db3c
  • Cluster Environment: AWS EKS
  • Host OS: Ubuntu 20.04.1 LTS kernel: 5.4.0-1029-aws
  • Linkerd version: 2.10.1

Possible solution

Additional context

I understand this is harmless when looking debug log. But it will create a lot of additional log and affect the logging collectors/storage and etc.

When I disable linker-proxy for linkerd-viz.prometheus pods then there are no such messages, also when I add following annotation:

config.linkerd.io/skip-outbound-ports: "4191"

It looks like proxy is affecting somehow outbound connections. This might explain this issue as well.

tarvip avatar Apr 16 '21 13:04 tarvip

@tarvip Do you see the logs lines upon application startup or does it only start occurring after some time? Does it ever resolve by itself? If not, does restarting the application pod or the Viz's Prometheus pod resolve it?

Similar to #5672 we've been unable to reproduce this issue so far so any details about the pods that you see this on would be super helpful. If you can provide a manifest that reproduces this that would be awesome.

For debugging this now, more verbose logs would help out. Similar to what you did for getting debug level logs, if you can up that to trace (linkerd_proxy_http=trace,hyper=trace,linkerd=info,warn) that would be awesome. Then once the problem appears, proxy logs from the application but also the Prometheus pod would be helpful.

Thanks for opening the separate issue and providing the information that you have.

kleimkuhler avatar Apr 16 '21 20:04 kleimkuhler

Do you see the logs lines upon application startup or does it only start occurring after some time?

I saw them since application startup. Also, not all pods that belonged to same Deployment had this issue.

Since I started playing with Viz's Prometheus to enable more logging for proxy I am unable to reproduce this issue. So, for now issue is gone.

I will keep monitoring the situation and update if I have more information (or close the issue).

tarvip avatar Apr 19 '21 08:04 tarvip

Ok thanks @tarvip. I'm not sure we want to close if you can't reproduce; this is still an issue, but just unfortunate if it goes away when logging is turned up. I'll keep an eye out for any further updates from you.

kleimkuhler avatar Apr 19 '21 12:04 kleimkuhler

I was able to capture something. foo-service pod: foo-service-65998f67c6-8lks5 with IP 10.1.17.19, it was running with:

config.linkerd.io/proxy-log-level: linkerd=debug,warn

In logs there were following lines:

foo-service-65998f67c6-8lks5 linkerd-proxy 2021-04-20T13:43:34.904615721Z {"timestamp":"[   173.288119s]","level":"DEBUG","fields":{"message":"Peeked bytes from TCP stream","sz":285},"target":"linkerd_tls::server","spans":[{"name":"daemon"},{"listen.addr":"0.0.0.0:4191","name":"admin"},{"client.addr":"10.1.22.239:53480","name":"accept"}],"threadId":"ThreadId(2)"}
foo-service-65998f67c6-8lks5 linkerd-proxy 2021-04-20T13:43:34.904635381Z {"timestamp":"[   173.288163s]","level":"DEBUG","fields":{"message":"Identified foreign SNI","sni":"prometheus.linkerd-viz.serviceaccount.identity.linkerd.cluster.local"},"target":"linkerd_tls::server","spans":[{"name":"daemon"},{"listen.addr":"0.0.0.0:4191","name":"admin"},{"client.addr":"10.1.22.239:53480","name":"accept"}],"threadId":"ThreadId(2)"}
foo-service-65998f67c6-8lks5 linkerd-proxy 2021-04-20T13:43:34.904644912Z {"timestamp":"[   173.288194s]","level":"DEBUG","fields":{"message":"DetectResult","protocol":"None","elapsed":"6.301µs"},"target":"linkerd_detect","spans":[{"name":"daemon"},{"listen.addr":"0.0.0.0:4191","name":"admin"},{"client.addr":"10.1.22.239:53480","name":"accept"}],"threadId":"ThreadId(2)"}
foo-service-65998f67c6-8lks5 linkerd-proxy 2021-04-20T13:43:34.904654032Z {"timestamp":"[   173.288219s]","level":"DEBUG","fields":{"message":"Failed to parse HTTP request; handling as HTTP/1"},"target":"linkerd_app::admin","spans":[{"name":"daemon"},{"listen.addr":"0.0.0.0:4191","name":"admin"},{"client.addr":"10.1.22.239:53480","name":"accept"}],"threadId":"ThreadId(2)"}
foo-service-65998f67c6-8lks5 linkerd-proxy 2021-04-20T13:43:34.904663632Z {"timestamp":"[   173.288238s]","level":"DEBUG","fields":{"message":"Creating HTTP service","version":"Http1"},"target":"linkerd_proxy_http::server","spans":[{"name":"daemon"},{"listen.addr":"0.0.0.0:4191","name":"admin"},{"client.addr":"10.1.22.239:53480","name":"accept"}],"threadId":"ThreadId(2)"}
foo-service-65998f67c6-8lks5 linkerd-proxy 2021-04-20T13:43:34.904671182Z {"timestamp":"[   173.288263s]","level":"DEBUG","fields":{"message":"Handling as HTTP","version":"Http1"},"target":"linkerd_proxy_http::server","spans":[{"name":"daemon"},{"listen.addr":"0.0.0.0:4191","name":"admin"},{"client.addr":"10.1.22.239:53480","name":"accept"}],"threadId":"ThreadId(2)"}
foo-service-65998f67c6-8lks5 linkerd-proxy 2021-04-20T13:43:34.904857814Z {"timestamp":"[   173.288359s]","level":"DEBUG","fields":{"message":"The client is shutting down the connection","res":"Err(hyper::Error(Parse(Method)))"},"target":"linkerd_proxy_http::server","spans":[{"name":"daemon"},{"listen.addr":"0.0.0.0:4191","name":"admin"},{"client.addr":"10.1.22.239:53480","name":"accept"}],"threadId":"ThreadId(2)"}
foo-service-65998f67c6-8lks5 linkerd-proxy 2021-04-20T13:43:34.904889685Z {"timestamp":"[   173.288405s]","level":"INFO","fields":{"message":"Connection closed","error":"invalid HTTP method parsed"},"target":"linkerd_app_core::serve","spans":[{"name":"daemon"},{"listen.addr":"0.0.0.0:4191","name":"admin"},{"client.addr":"10.1.22.239:53480","name":"accept"}],"threadId":"ThreadId(2)"}

and prometheus proxy was running with:

config.linkerd.io/proxy-log-level: linkerd_proxy_http=trace,hyper=trace,linkerd=debug,warn

I have attached logs from prometheus linkerd-proxy where timestamp is between 2021-04-20T13:43:34.000205856Z and 2021-04-20T13:43:35.989621424Z as prom-proxy.log.gz

There are some interesting log lines regarding corrupt messages:

prometheus-68dccd4fdf-h6zc8 linkerd-proxy 2021-04-20T13:43:34.403390755Z {"timestamp":"[  1939.467791s]","level":"DEBUG","fields":{"message":"Failed to connect","error":"received corrupt message"},"target":"linkerd_reconnect::service","spans":[{"name":"outbound"},{"client.addr":"10.1.22.239:41056","name":"accept"},{"orig_dst":"10.1.17.19:4191","name":"server"},{"v":"1.x","name":"http"},{"server.addr":"10.1.17.19:4191","name":"endpoint"}],"threadId":"ThreadId(1)"}

Also there was another pod having issues at the same time: bar-service-789fbbdb59-5q7jd with IP 10.1.23.133, but this one had no debug log enabled in proxy.

tarvip avatar Apr 20 '21 14:04 tarvip

Hi, we have the same issue after upgrading to linkerd 2.10.1 in our testing environments. Logs have many "Connection closed error=invalid HTTP method parsed" errors. Pods seem to be randomly affected, but in general the issue is reproducible, when I restart some deployment's pods couple of times. I enabled tracing configuration for one of the deployments and this is what I got from logs:

[   276.292622s] TRACE ThreadId(02) linkerd_proxy_http::detect: Reading capacity=1024
[   276.292649s] TRACE ThreadId(02) linkerd_proxy_http::detect: Read sz=301
[   276.292655s] TRACE ThreadId(02) linkerd_proxy_http::detect: Checking H2 preface
[   276.292659s] TRACE ThreadId(02) linkerd_proxy_http::detect: Parsing HTTP/1 message
[   276.292664s] TRACE ThreadId(02) linkerd_proxy_http::detect: Not HTTP
[   276.292669s] DEBUG ThreadId(02) linkerd_proxy_http::server: Creating HTTP service version=Http1
[   276.292683s] DEBUG ThreadId(02) linkerd_proxy_http::server: Handling as HTTP version=Http1
[   276.292702s] TRACE ThreadId(02) hyper::proto::h1::conn: Conn::read_head
[   276.292717s] TRACE ThreadId(02) parse_headers: hyper::proto::h1::role: Request.parse([Header; 100], [u8; 301])
[   276.292729s] TRACE ThreadId(02) hyper::proto::h1::conn: State::close_read()
[   276.292734s] DEBUG ThreadId(02) hyper::proto::h1::conn: parse error (invalid HTTP method parsed) with 301 bytes
[   276.292739s] DEBUG ThreadId(02) hyper::proto::h1::role: sending automatic response (400 Bad Request) for parse error
[   276.292747s] TRACE ThreadId(02) encode_headers: hyper::proto::h1::role: Server::encode status=400, body=None, req_method=None
[   276.292786s] DEBUG ThreadId(02) hyper::proto::h1::io: flushed 84 bytes
[   276.292811s] TRACE ThreadId(02) hyper::proto::h1::conn: flushed({role=server}): State { reading: Closed, writing: Closed, keep_alive: Disabled, error: hyper::Error(Parse(Method)) }
[   276.292839s] TRACE ThreadId(02) hyper::proto::h1::conn: shut down IO complete
[   276.292884s] DEBUG ThreadId(02) linkerd_proxy_http::server: The client is shutting down the connection res=Err(hyper::Error(Parse(Method)))
[   276.292987s]  INFO ThreadId(02) linkerd_app_core::serve: Connection closed error=invalid HTTP method parsed
[   276.482025s] TRACE ThreadId(01) hyper::client::pool: idle interval checking for expired
[   276.794489s] TRACE ThreadId(02) linkerd_proxy_http::detect: Reading capacity=1024
[   276.794516s] TRACE ThreadId(02) linkerd_proxy_http::detect: Read sz=301
[   276.794520s] TRACE ThreadId(02) linkerd_proxy_http::detect: Checking H2 preface
[   276.794524s] TRACE ThreadId(02) linkerd_proxy_http::detect: Parsing HTTP/1 message
[   276.794527s] TRACE ThreadId(02) linkerd_proxy_http::detect: Not HTTP
[   276.794532s] DEBUG ThreadId(02) linkerd_proxy_http::server: Creating HTTP service version=Http1
[   276.794544s] DEBUG ThreadId(02) linkerd_proxy_http::server: Handling as HTTP version=Http1
[   276.794565s] TRACE ThreadId(02) hyper::proto::h1::conn: Conn::read_head
[   276.794579s] TRACE ThreadId(02) parse_headers: hyper::proto::h1::role: Request.parse([Header; 100], [u8; 301])
[   276.794603s] TRACE ThreadId(02) hyper::proto::h1::conn: State::close_read()
[   276.794609s] DEBUG ThreadId(02) hyper::proto::h1::conn: parse error (invalid HTTP method parsed) with 301 bytes
[   276.794613s] DEBUG ThreadId(02) hyper::proto::h1::role: sending automatic response (400 Bad Request) for parse error
[   276.794621s] TRACE ThreadId(02) encode_headers: hyper::proto::h1::role: Server::encode status=400, body=None, req_method=None
[   276.794672s] DEBUG ThreadId(02) hyper::proto::h1::io: flushed 84 bytes
[   276.794686s] TRACE ThreadId(02) hyper::proto::h1::conn: flushed({role=server}): State { reading: Closed, writing: Closed, keep_alive: Disabled, error: hyper::Error(Parse(Method)) }
[   276.794718s] TRACE ThreadId(02) hyper::proto::h1::conn: shut down IO complete
[   276.794736s] DEBUG ThreadId(02) linkerd_proxy_http::server: The client is shutting down the connection res=Err(hyper::Error(Parse(Method)))
[   276.794780s]  INFO ThreadId(02) linkerd_app_core::serve: Connection closed error=invalid HTTP method parsed

I hope it helps to troubleshoot, thanks.

alekseiplotnikov avatar Apr 20 '21 15:04 alekseiplotnikov

Pods seem to be randomly affected

In our case also other pods are randomly affected like I mentioned here.

tarvip avatar Apr 20 '21 16:04 tarvip

Here are the logs for 2 different pods.

(note: using linkerd edge-21.4.2)

It looks like the prometheus proxy is expecting 10.16.139.126 to be default.batch.serviceaccount.identity.linkerd.cluster.local when it should actually be default.person.serviceaccount.identity.linkerd.cluster.local

dig +short -x 10.16.139.126
10-16-139-126.web.person.svc.cluster.local.
10-16-139-126.metrics.person.svc.cluster.local.

Person app (IP addr: 10.16.139.126)

[  2722.491638s] TRACE ThreadId(01) want: signal: Want
[  2722.491645s] TRACE ThreadId(01) hyper::proto::h1::conn: flushed({role=client}): State { reading: Init, writing: Init, keep_alive: Idle }
[  2722.491651s] TRACE ThreadId(01) linkerd_cache: Reset
[  2722.689902s] TRACE ThreadId(02) daemon:admin{listen.addr=0.0.0.0:4191}: mio::poll: registering event source with poller: token=Token(989855746), interests=READABLE | WRITABLE
[  2722.856698s] DEBUG ThreadId(02) daemon:admin{listen.addr=0.0.0.0:4191}:accept{client.addr=10.16.174.49:56810}: linkerd_tls::server: Peeked bytes from TCP stream sz=276
[  2722.856730s] TRACE ThreadId(02) daemon:admin{listen.addr=0.0.0.0:4191}:accept{client.addr=10.16.174.49:56810}: linkerd_tls::server::client_hello: parse_sni: parsed correctly up to SNI sni=Some(ServerId("default.batch.serviceaccount.identity.linkerd.cluster.local"))
[  2722.856740s] DEBUG ThreadId(02) daemon:admin{listen.addr=0.0.0.0:4191}:accept{client.addr=10.16.174.49:56810}: linkerd_tls::server: Identified foreign SNI sni=default.batch.serviceaccount.identity.linkerd.cluster.local
[  2722.856757s] TRACE ThreadId(02) daemon:admin{listen.addr=0.0.0.0:4191}:accept{client.addr=10.16.174.49:56810}: linkerd_detect: Starting protocol detection
[  2722.856762s] TRACE ThreadId(02) daemon:admin{listen.addr=0.0.0.0:4191}:accept{client.addr=10.16.174.49:56810}: linkerd_proxy_http::detect: Reading capacity=1024
[  2722.856769s] TRACE ThreadId(02) daemon:admin{listen.addr=0.0.0.0:4191}:accept{client.addr=10.16.174.49:56810}: linkerd_proxy_http::detect: Read sz=276
[  2722.856772s] TRACE ThreadId(02) daemon:admin{listen.addr=0.0.0.0:4191}:accept{client.addr=10.16.174.49:56810}: linkerd_proxy_http::detect: Checking H2 preface
[  2722.856775s] TRACE ThreadId(02) daemon:admin{listen.addr=0.0.0.0:4191}:accept{client.addr=10.16.174.49:56810}: linkerd_proxy_http::detect: Parsing HTTP/1 message
[  2722.856777s] TRACE ThreadId(02) daemon:admin{listen.addr=0.0.0.0:4191}:accept{client.addr=10.16.174.49:56810}: linkerd_proxy_http::detect: Not HTTP
[  2722.856781s] DEBUG ThreadId(02) daemon:admin{listen.addr=0.0.0.0:4191}:accept{client.addr=10.16.174.49:56810}: linkerd_detect: DetectResult protocol=None elapsed=19.534µs
[  2722.856787s] DEBUG ThreadId(02) daemon:admin{listen.addr=0.0.0.0:4191}:accept{client.addr=10.16.174.49:56810}: linkerd_app::admin: Failed to parse HTTP request; handling as HTTP/1
[  2722.856791s] DEBUG ThreadId(02) daemon:admin{listen.addr=0.0.0.0:4191}:accept{client.addr=10.16.174.49:56810}: linkerd_proxy_http::server: Creating HTTP service version=Http1
[  2722.856802s] TRACE ThreadId(02) daemon:admin{listen.addr=0.0.0.0:4191}:accept{client.addr=10.16.174.49:56810}: linkerd_detect: Dispatching connection
[  2722.856821s] DEBUG ThreadId(02) daemon:admin{listen.addr=0.0.0.0:4191}:accept{client.addr=10.16.174.49:56810}: linkerd_proxy_http::server: Handling as HTTP version=Http1
[  2722.856841s] TRACE ThreadId(02) daemon:admin{listen.addr=0.0.0.0:4191}:accept{client.addr=10.16.174.49:56810}: hyper::proto::h1::conn: Conn::read_head
[  2722.856851s] TRACE ThreadId(02) daemon:admin{listen.addr=0.0.0.0:4191}:accept{client.addr=10.16.174.49:56810}:parse_headers: hyper::proto::h1::role: Request.parse([Header; 100], [u8; 276])
[  2722.856860s] TRACE ThreadId(02) daemon:admin{listen.addr=0.0.0.0:4191}:accept{client.addr=10.16.174.49:56810}: hyper::proto::h1::conn: State::close_read()
[  2722.856873s] DEBUG ThreadId(02) daemon:admin{listen.addr=0.0.0.0:4191}:accept{client.addr=10.16.174.49:56810}: hyper::proto::h1::conn: parse error (invalid HTTP method parsed) with 276 bytes
[  2722.856878s] DEBUG ThreadId(02) daemon:admin{listen.addr=0.0.0.0:4191}:accept{client.addr=10.16.174.49:56810}: hyper::proto::h1::role: sending automatic response (400 Bad Request) for parse error
[  2722.856884s] TRACE ThreadId(02) daemon:admin{listen.addr=0.0.0.0:4191}:accept{client.addr=10.16.174.49:56810}:encode_headers: hyper::proto::h1::role: Server::encode status=400, body=None, req_method=None
[  2722.856919s] DEBUG ThreadId(02) daemon:admin{listen.addr=0.0.0.0:4191}:accept{client.addr=10.16.174.49:56810}: hyper::proto::h1::io: flushed 84 bytes
[  2722.856924s] TRACE ThreadId(02) daemon:admin{listen.addr=0.0.0.0:4191}:accept{client.addr=10.16.174.49:56810}: hyper::proto::h1::conn: flushed({role=server}): State { reading: Closed, writing: Closed, keep_alive: Disabled, error: hyper::Error(Parse(Method)) }
[  2722.856942s] TRACE ThreadId(02) daemon:admin{listen.addr=0.0.0.0:4191}:accept{client.addr=10.16.174.49:56810}: hyper::proto::h1::conn: shut down IO complete
[  2722.856948s] DEBUG ThreadId(02) daemon:admin{listen.addr=0.0.0.0:4191}:accept{client.addr=10.16.174.49:56810}: linkerd_proxy_http::server: The client is shutting down the connection res=Err(hyper::Error(Parse(Method)))
[  2722.856958s] TRACE ThreadId(02) daemon:admin{listen.addr=0.0.0.0:4191}:accept{client.addr=10.16.174.49:56810}: mio::poll: deregistering event source from poller
[  2722.856983s]  INFO ThreadId(02) daemon:admin{listen.addr=0.0.0.0:4191}:accept{client.addr=10.16.174.49:56810}: linkerd_app_core::serve: Connection closed error=invalid HTTP method parsed

Prometheus proxy logs

[293855.828722s] DEBUG ThreadId(01) server{orig_dst=10.16.139.126:4191}:h2: linkerd_proxy_transport::connect: Connected local.addr=10.16.174.49:42554 keepalive=Some(10s)
[293855.828738s] DEBUG ThreadId(01) server{orig_dst=10.16.139.126:4191}:h2: rustls::client::hs: No cached session for DNSNameRef("default.batch.serviceaccount.identity.linkerd.cluster.local")
[293855.828742s] DEBUG ThreadId(01) server{orig_dst=10.16.139.126:4191}:h2: rustls::client::hs: Not resuming any session
[293855.980136s] DEBUG ThreadId(01) server{orig_dst=10.16.139.126:4191}: linkerd_reconnect::service: Failed to connect error=received corrupt message
[293855.980147s] DEBUG ThreadId(01) server{orig_dst=10.16.139.126:4191}: linkerd_reconnect::service: Recovering
[293856.481027s] DEBUG ThreadId(01) server{orig_dst=10.16.139.126:4191}: linkerd_proxy_http::client: Building HTTP client settings=OrigProtoUpgrade
[293856.481045s] DEBUG ThreadId(01) server{orig_dst=10.16.139.126:4191}: linkerd_tls::client: Initiating TLS connection server.id=default.batch.serviceaccount.identity.linkerd.cluster.local
[293856.481048s] DEBUG ThreadId(01) server{orig_dst=10.16.139.126:4191}: linkerd_proxy_transport::connect: Connecting server.addr=10.16.139.126:4191
[293856.481597s] DEBUG ThreadId(01) server{orig_dst=10.16.139.126:4191}:h2: linkerd_proxy_transport::connect: Connected local.addr=10.16.174.49:42624 keepalive=Some(10s)
[293856.481615s] DEBUG ThreadId(01) server{orig_dst=10.16.139.126:4191}:h2: rustls::client::hs: No cached session for DNSNameRef("default.batch.serviceaccount.identity.linkerd.cluster.local")
[293856.481620s] DEBUG ThreadId(01) server{orig_dst=10.16.139.126:4191}:h2: rustls::client::hs: Not resuming any session
[293856.485220s] DEBUG ThreadId(01) server{orig_dst=10.16.139.126:4191}: linkerd_reconnect::service: Failed to connect error=received corrupt message
[293856.485228s] DEBUG ThreadId(01) server{orig_dst=10.16.139.126:4191}: linkerd_reconnect::service: Recovering
[293857.133931s] DEBUG ThreadId(01) server{orig_dst=10.16.139.126:4191}: hyper::proto::h1::io: parsed 5 headers
[293857.133940s] DEBUG ThreadId(01) server{orig_dst=10.16.139.126:4191}: hyper::proto::h1::conn: incoming body is empty
[293857.135647s] DEBUG ThreadId(01) server{orig_dst=10.16.139.126:4191}: linkerd_proxy_http::client: Building HTTP client settings=OrigProtoUpgrade
[293857.135659s] DEBUG ThreadId(01) server{orig_dst=10.16.139.126:4191}: linkerd_tls::client: Initiating TLS connection server.id=default.batch.serviceaccount.identity.linkerd.cluster.local
[293857.135661s] DEBUG ThreadId(01) server{orig_dst=10.16.139.126:4191}: linkerd_proxy_transport::connect: Connecting server.addr=10.16.139.126:4191
[293857.158661s] DEBUG ThreadId(01) server{orig_dst=10.16.139.126:4191}: tower::buffer::worker: service.ready=true processing request
[293857.158674s] DEBUG ThreadId(01) server{orig_dst=10.16.139.126:4191}:endpoint{server.addr=10.16.139.126:4191}:orig-proto-upgrade: linkerd_proxy_http::client: method=GET uri=http://10.16.139.126:4191/metrics version=HTTP/1.1
[293857.158679s] DEBUG ThreadId(01) server{orig_dst=10.16.139.126:4191}:endpoint{server.addr=10.16.139.126:4191}:orig-proto-upgrade: linkerd_proxy_http::client: headers={"host": "10.16.139.126:4191", "user-agent": "Prometheus/2.19.3", "accept": "application/openmetrics-text; version=0.0.1,text/plain;version=0.0.4;q=0.5,*/*;q=0.1", "accept-encoding": "gzip", "x-prometheus-scrape-timeout-seconds": "10.000000"}
[293857.158687s] DEBUG ThreadId(01) server{orig_dst=10.16.139.126:4191}:endpoint{server.addr=10.16.139.126:4191}:orig-proto-upgrade: linkerd_proxy_http::orig_proto: Upgrading request version=HTTP/1.1 absolute_form=false

mattatcha avatar Apr 20 '21 19:04 mattatcha

Thanks for all the feedback on this the logs are super helpful. After the last comment from @mattatcha I'm realizing that a proxy (it tends to always be Viz Prometheus's proxy) is setting the wrong SNI when initiating a TLS connection. We can see this with the Identified foreign SNI log line—I missed then when originally looking so I'm sorry about that!

In @tarvip's case, the Prometheus proxy is setting the SNI for it's own identity (prometheus.linkerd-viz.serviceaccount.identity.linkerd.cluster.local) and in @mattatcha's case it seems to just be the identity for another pod.

Right now I'm not sure why this is so reproducible for some installations and not others. I have tried reproducing this on on my own several times now and have not been able to. It's also interesting that within a deployment it sets it correctly for some pods but not others.

I'd be surprised if this is related to the affected pods restarting; I say this because it's not really staleness that we are seeing—it's just the wrong SNI being set by the Prometheus proxy.

@tarvip (or anyone else on this thread) the verbose logs that you provided from the Prometheus proxy are super and I can see where this is happening but I'm still not exactly sure why. If this is semi-reproducible for you is there any chance you could bump the logs up one more on the Prometheus deployment? Specifically, I'm looking for trace in the entire proxy—not just linkerd_proxy_http. The annotation value would be : linkerd=trace,hyper=trace,warn.

No problem if you're concerned about log file size and would prefer not to! What you've provided has already been helpful so I can continue looking at things with what we have now.

kleimkuhler avatar Apr 21 '21 02:04 kleimkuhler

I think this issue happens if restarting multiple pods at the same time and new pod gets recently terminated pod IP. In this case prometheus proxy is using wrong SNI. I think you could reproduce it if you set your IP pool small enough so that when restarting multiple pods at the same time they will get recently terminated pod IP.

I was able to capture some logs with linkerd=trace,hyper=trace,warn. See file prom-proxy-2.log.gz.

For example at April 21st 2021, 08:22:39.467 +00:00 on destination pod bar-service-7f7bf4db59-bh8g4 had this issue. This destination pod had IP 10.0.34.243, but when I check kube_pod_info metrics for this IP in (non-linkerd) prometheus, I can see that it was attached to another pod before it was created and now proxy is using this old pod SNI. See here:

prometheus-c68bc7bdb-8dl4p linkerd-proxy 2021-04-21T08:22:39.466803177Z {"timestamp":"[   537.524656s]","level":"DEBUG","fields":{"message":"Initiating TLS connection","server.id":"foo-service.dev.serviceaccount.identity.linkerd.cluster.local"},"target":"linkerd_tls::client","spans":[{"name":"outbound"},{"client.addr":"10.0.8.159:58842","name":"accept"},{"orig_dst":"10.0.34.243:4191","name":"server"},{"v":"1.x","name":"http"},{"server.addr":"10.0.34.243:4191","name":"endpoint"}],"threadId":"ThreadId(1)"}

It supposed to use bar-service actually as this IP belonged to bar-service's pod at that time, but foo-service pod had this IP previously.

tarvip avatar Apr 21 '21 09:04 tarvip

FYI I used trace as the log level for the logs I posted above, I don't think I tried using linkerd=trace,hyper=trace,warn though.

mattatcha avatar Apr 21 '21 17:04 mattatcha

@tarvip Yep that makes sense too. The SNI isn't necessarily getting set incorrectly if it was correct before, but not torn down properly after the pod restarted. I'm working on a repro for this right now and will keep you updated with what I find.

kleimkuhler avatar Apr 21 '21 18:04 kleimkuhler

We had the same issue.

Env: AWS EKS v1.18, Linkerd stable-2.10.1

How did we resolve it? We checked K8S Nodes' config. Found that, there is a config item "clusterDNS" with a strange IP as its value. Remove the config item "clusterDNS", install LocalDNS ( maybe needn't ). Everything is OK.

palmtoy avatar Apr 23 '21 07:04 palmtoy

There is not a solution for this yet but I have a reliable reproduction and can explain what is happening. This happens most often with the Viz extension's Prometheus, but any proxy is susceptible to the issue.

  1. The Prometheus deployment is rolled and the new Prometheus pod (say 10.0.0.2) starts scraping the old Prometheus pod (say 10.0.0.1) at 10.0.0.1:9090 as it is terminating. It opens a TLS connection with the identity of the pod at the time which is prometheus.linkerd-viz.serviceaccount.identity.linkerd.cluster.local
  2. The old Prometheus pod finishes terminating and 10.0.0.1 does not map to any pod. However, this gets stuck in the new Prometheus pod's cache and it infinitely tries to reconnect to 10.0.0.1:9090.
  3. Eventually a new pod get's assigned 10.0.0.1 and it may not even serve anything on 9090, but the Prometheus immediately starts sending scrape requests to 10.0.0.1:9090 with the old SNI.
  4. These requests are logged as invalid HTTP method parsed because the admin server falls back to HTTP/1 when in fact the requests are HTTP/2. Falling back to HTTP/2 would not fix this issue because it's the wrong SNI when initiating the TLS connection.

To fix this, the new Prometheus pod should of course not keep trying to reconnect to 10.0.0.1:9090. I'm still working on a fix in the proxy to prevent this reconnect issue for services in the cache, but I hope to post an update here soon with a change. Thanks for all the helpful logs on this.

kleimkuhler avatar Apr 23 '21 13:04 kleimkuhler

We're running Azure AKS 1.18.10 and have seen "linkerd_app_core::serve: Connection closed error=invalid HTTP method parsed" and "linkerd_app_core::serve: Connection closed error=TLS detection timeout" errors after updating from 2.9.3 (to fix another bug/error) to 2.10.1.

Our initial workaround (based on suggestion by a related issues, see URLs below) was to opaque port 4191 on all our namespaces using Linkerd, which helped but we're now seeing those errors are also on the destination and identity pods in the linkerd namespace.

The errors mention that they're closing those connection. Is that accurate, since protocol detection in 2.10.1 should fail open if they can't detect a connection in 10 seconds?

https://www.gitmemory.com/issue/linkerd/linkerd2/6037/822269057 https://github.com/linkerd/linkerd2/issues/5672#issuecomment-818690872

Update:

We disabled proxy on the "linkerd-viz" prometheus deployment and opaqued port 4191 on the "linkerd-viz namespace" to try and reduce/eliminate these errors. It did reduce the amount of errors, but we are still seeing "linkerd_app_core::serve: Connection closed error=TLS detection timeout" errors on the linkerd destination pods so far.

lupusllc avatar Apr 28 '21 19:04 lupusllc

@lupusllc Thanks for adding in here. This issue should be fixed in the edge that was released yesterday edge-21.4.5. This will also be available in a stable-2.10.2 at some point soon. I'll wait to close this issue until that is released.

For those who have been involved in this issue, this was fixed in tower-rs/tower#581 which is a proxy dependency. Reconnects—which are the background tasks in this context—were not being aborted properly, so they would get stuck in an infinite reconnect loop.

This most often happened with Viz's Prometheus and resulted in the errors a lot of you have seen. What would happen is a pod 10.0.0.1 would be scraped by Prometheus at 10.0.0.1:4191 with some SNI foo. After some point, that pod is terminated but Prometheus's proxy keeps trying to reconnect to 10.0.0.1:4191. Eventually, a new pod takes that IP and all of a sudden the Prometheus's proxy starts sending requests to the new pod at 10.0.0.1:4191 with foo SNI. But since this is a new pod, it may have bar identity. This results in the error.

This issue is not specific to Prometheus's proxy so we're hoping this also cleans up a lot of the fail fast errors in general.

kleimkuhler avatar Apr 30 '21 13:04 kleimkuhler

@tarvip @lupusllc Have you had a chance to test the edge-21.4.5 release -- or at least its proxy (which is compatible with stable-2.10.x and stable-2.9.x) -- we plan to release a new stable release with these fixes, but it would be great to get confirmation that the problem is resolved by these changes.

olix0r avatar May 07 '21 16:05 olix0r

@olix0r I deployed edge-21.4.5 in our dev env this morning (previously running stable-2.10.1, and the log messages have disappeared. Went from ~10K every 15m to under 200.

athak avatar May 07 '21 16:05 athak

I deployed just proxy edge-21.4.5 few days ago with stable-2.10.1 to our dev env, so far it looks good, tried to restart a lot of pods at the same, no "invalid HTTP method parsed" in logs.

tarvip avatar May 07 '21 18:05 tarvip

Glad to hear thanks for letting us know.

kleimkuhler avatar May 07 '21 19:05 kleimkuhler

Closing this as stable-2.10.2 has been released!

kleimkuhler avatar May 19 '21 14:05 kleimkuhler