cj1128
I implemented a simple echo server in Elixir, repo is here GitHub - cj1128/echo_server · GitHub.
When I test it using echo hello | nc localhost 4100, everything is fine.
But when I use a custom client which concurrently starts 10 connections, I got below error, so confused.
13:25:12.299 [error] Task #PID<0.108.0> started from #PID<0.95.0> terminating
** (MatchError) no match of right hand side value: {:error, :closed}
lib/client.exs:14: Client.run/0
(elixir 1.14.3) lib/task/supervised.ex:89: Task.Supervised.invoke_mfa/2
(elixir 1.14.3) lib/task/supervised.ex:34: Task.Supervised.reply/4
(stdlib 4.2) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
Function: #Function<1.124100197/0 in Client.run>
Args: []
13:25:12.299 [error] Task #PID<0.107.0> started from #PID<0.95.0> terminating
** (MatchError) no match of right hand side value: {:error, :closed}
lib/client.exs:14: Client.run/0
(elixir 1.14.3) lib/task/supervised.ex:89: Task.Supervised.invoke_mfa/2
(elixir 1.14.3) lib/task/supervised.ex:34: Task.Supervised.reply/4
(stdlib 4.2) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
Function: #Function<1.124100197/0 in Client.run>
Args: []
I tried
sysctl kern.ipc.somaxconn=1000increase TCP queue size- Add an accept pool, so multiple processes are accepting connections
none of them worked, still got those errors.
Env
OS: ARM64 and X64 MacOS 12.3
$ elixir --version
Erlang/OTP 25 [erts-13.1.3] [source] [64-bit] [smp:10:10] [ds:10:10:10] [async-threads:1] [jit] [dtrace]
Elixir 1.14.3 (compiled with Erlang/OTP 25)
How to run
$ mix run --no-halt
# in another shell
$ elixir lib/client.exs
Summary
This text will be hidden
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Kia ora,
We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Hello,
I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter).
The diffic...
New
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
Other Trending Topics
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
ICal is a library for interacting with iCalendar data. It parses iCalendars into typed Elixir structs via ICal.from_ics, and can prepare ...
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
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #ai
- #phoenix_html
- #elixirconf-us
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 9- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
al2o3cr
EchoServercallsacceptin one process, thenrecvin a different, newly-spawned one.The process that calls
accept“owns” the connection (see also recent discussion here).cj1128
Hi, thanks for you reply.
My code is not the same as the linked one, the main process which owns the connection is always alive, so it should not cause the socket to be closed.
I modified the code to use
:gen_tcp.controlling_processand I still got the error.When I ran the client, sometimes it’s all fine, sometimes I got
{:error, :closed}, and sometimes I got{:error, :econnreset}.cj1128
I wrote a simple echo server in JS and I tested it using the same client
elixir lib/client.exsand I found that no error showed, so I am sure that something is wrong with my server code, but I am really confused what is going wrong.jnnks
This snippet works for me using telnet.
Could you reduce your code a bit more?
cj1128
Hi,
telnetis fine, but the server returned error when it was concurrently requested.This is the reduced code.
jnnks
This example also works fine for me
I ran it in two separate iex sessions.
cj1128
This is very weird, can you try to run the client multiple times? it’s not always erroring out.
If I ran the client against the node version server, then i will always succeed.
jnnks
Running multiple clients also works for me.
Maybe you can try to isolate your error even further. No Logger, no modules, etc.
As long as the behavior is inconsistent I don’t think we can help you that well.
cj1128
Finally found the reason.
The default
backlogparam of:gen_tcpis 5 and this is too small. When the TCP accept queue is full, we will get error like “error: closed”