stefkin
stefkin

Reputation: 679

Cowboy returns 400 without headers

AWS HealthCheck endpoint doesn't send any headers which causes Cowboy (v 1.1.2) to return 400. This is causing container restarts.

Is there any way around the issue?

Related github issue: https://github.com/phoenixframework/phoenix/issues/2437

curl request to reproduce the error:

   curl http://localhost:4000/ping  -H 'Host:'

Log:

[error] Cowboy returned 400 and there are no headers in the connection.

This may happen if Cowboy is unable to parse the request headers,
for example, because there are too many headers or the header name
or value are too large (such as a large cookie).

You can customize those values when configuring your http/https
server. The configuration option and default values are shown below:

    protocol_options: [
      max_header_name_length: 64,
      max_header_value_length: 4096,
      max_headers: 100
    ]

endpoint configuration:

 config :my_app, MyAppWeb.Endpoint,
   load_from_system_env: true,
   url: [host: System.get_env("MY_HOST"), port: 443],
   force_ssl: [rewrite_on: [:x_forwarded_proto]]

Upvotes: 2

Views: 827

Answers (1)

stefkin
stefkin

Reputation: 679

I ended up running the server with the following Endpoint config:

config :my_app, MyAppWeb.Endpoint,
  load_from_system_env: true,
  http: [port: 4000]

and the problem was resolved.

It probably had something to do with the fact that cowboy was running https server behind ELB.

Upvotes: 3

Related Questions