mikejm
Simple Bandit HTTP Server test code giving "econnaborted" error?
I have started a basic HTTP Server as per the following tutorials:
#//PLUG MODULE FOR BANDIT https://hexdocs.pm/plug/readme.html
defmodule MyPlug do
import Plug.Conn
def init(options) do
# initialize options
options
end
def call(conn, _opts) do
conn
|> put_resp_content_type("text/plain")
|> send_resp(200, "Hello world")
end
end
#//MAIN MODULE
defmodule ServerTest do
def startHttpServer do
IO.puts("Try Start HTTP Server");
webserver = {Bandit, plug: MyPlug, scheme: :http, port: 4000 }
supervisorOpts = [strategy: :one_for_one ]
{:ok, _} = Supervisor.start_link([webserver], supervisorOpts)
IO.puts("Plug now running on localhost:4000");
#Process.sleep(:infinity)
end
end
This works, in that if I run the project and then ServerTest.startHttpServer() and go to localhost:4000 I get a “Hello world” back. But I am also getting this:
21:11:37.278 [error] GenServer #PID<0.554.0> terminating
** (stop) :econnaborted
Last message: {:tcp_error, #Port<0.3>, :econnaborted}
State: {%ThousandIsland.Socket{socket: #Port<0.3>, transport_module: ThousandIsland.Transports.TCP, read_timeout: 60000, silent_terminate_on_error: false, span: %ThousandIsland.Telemetry{span_name: :connection, telemetry_span_context: #Reference<0.267163659.1006895106.157280>, start_time: -5764607406509056, start_metadata: %{telemetry_span_context: #Reference<0.267163659.1006895106.157280>, parent_telemetry_span_context: #Reference<0.267163659.1006895106.157220>, remote_address: {127, 0, 0, 1}, remote_port: 63311}}}, %{opts: %{http: [], http_1: [], http_2: [], websocket: []}, plug: {MyPlug, []}, handler_module: Bandit.HTTP1.Handler, http_1_enabled: true, http_2_enabled: true, requests_processed: 2}}
21:13:32.629 [error] ** (Bandit.HTTPError) Header read socket error: :closed
What does this all mean? What is wrong with the above code? Thanks for any help.
I find it funny also because I haven’t started any GenServer, so I presume this is a GenServer being started by Plug/Bandit? What is the problem?
Popular in Questions
Hi!
In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir?
Searched the docs for ip address and the web, no good results.
Thanks!
New
Hi everyone!
I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
Good day to you all.
I have been struggling to get a query involving like and ilike to work.
Can anyone assist me on this, please?
pro...
New
Hi,
I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
Other popular topics
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine)
This is a plugin that adds support for Elixir to JetBrains IntelliJ...
New
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
New
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
Hi All,
I set a environment variables in dev.exs , like below code.
when i start server, how can i set the ${enable} value?
thanks.
d...
New
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
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #hex
- #security









