michaelterryio

michaelterryio

Plug/Cowboy "connection closed" fixed with Nginx proxy server

We have a service with a Plug interface. It calls a vendor API with requests and then later receives callbacks with payloads responding to the requests.

A couple weeks ago, the vendor’s error page started reporting that it was getting “connection closed” when hitting our callback endpoint about 1% of the time. This was odd to us because nothing had changed. We hadn’t made a commit on this service in over a year and it’s running on the same EC2 instance it always has.

The fix was to put an Nginx proxy server in front of the Elixir service.

While it’s nice to have a fix, why it happened is still a mystery. What would have been a good way to debug this? Is it more likely a Plug or Cowboy issue? My best guess is that the vendor changed or upgraded their HTTP client and there’s an incompatibility with Cowboy. Their support did not suggest this as a possibility when we talked to them, though. They felt there was something wrong with our application–we talked to them before the proxy fix, however. Any other thoughts?

Most Liked

jakemorrison

jakemorrison

That sounds more like network problems than an application incompatibility. Is there some more specific error code that they are getting? Or just an HTTP timeout?

You can log the whole conn and get details about their HTTP request.

Using Nginx adds a “buffer” as it will queue requests for a while waiting for the back end to respond. That can end up being a problem on high volume applications, and things get more reliable when we remove Nginx. https://www.cogini.com/blog/serving-your-phoenix-app-with-nginx/

Cowboy is generally a pretty compatible HTTP stack, though sometimes you need to set protocol options to handle things that Nginx was handling for you. e.g.

config :foo, FooWeb.Endpoint,
  http: [
    compress: true,
    protocol_options: [max_keepalive: 5_000_000]
  ],
jakemorrison

jakemorrison

I guess SSL/TLS version or parameters. One of the machines in their pool is requiring something stronger than what Cowboy is configured for, or vice versa.

Where Next?

Popular in Questions Top

LegitStack
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it. I’m very interested in Elixir,...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
logicmason
Hi there, I'm working through my first release with elixir/phoenix. I've built a release with distillery and found that it crashes when I...
New
Kagamiiiii
Student & New to elixir. Nice language. I want to convert a english character, e.g. “a”, which is stored in a variable, to it’s asci...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New

Other popular topics Top

chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
New
yurko
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New

We're in Beta

About us Mission Statement