Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resource temporarily unavailable with default unix socket configuration #1449

Closed
eprothro opened this issue Nov 8, 2017 · 9 comments
Closed
Assignees

Comments

@eprothro
Copy link
Contributor

eprothro commented Nov 8, 2017

During some recent load testing and optimization, we switched from a TCP socket to UNIX socket.

With high throughput (>500 connections/sec), the client (nginx reverse proxy in this case) experienced errors connecting to the socket. We saw no such issues with the TCP socket.

connect() to unix:/path/to/socket/puma.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client...

Trying to isolate/debug I noticed that the default backlog for unix sockets is nil (not 1024 like with TCP). And further, that with a falsy backlog, listen is not called on the socket.

Setting a backlog (via bind path uri query param) resolved the connection issues in our tests.

Excuse any ignorance as I'm no unix socket expert, but is the backlog=nil default and not calling listen intentional and desirable for UNIX sockets?

If it is intentional/recommended, how should users expect to buffer bursty clients?

If not, I'm happy to issue PR.

@nateberkopec
Copy link
Member

Trying to isolate/debug I noticed that the default backlog for unix sockets is nil

Hm, that does seem wrong.

@nateberkopec nateberkopec assigned nateberkopec and unassigned evanphx Nov 20, 2017
@nateberkopec
Copy link
Member

@eprothro I talked to Evan about this, he said this behavior is not intentional and is definitely a bug. We should change the default Unix backlog to 1024.

eprothro added a commit to eprothro/puma that referenced this issue Nov 28, 2017
eprothro added a commit to eprothro/puma that referenced this issue Nov 28, 2017
eallison91 pushed a commit to eallison91/puma that referenced this issue Nov 29, 2017
@ernestojpg
Copy link

Hi all, I have updated to latest version of Puma (3.12.0) and I'm still having the same issue: Nginx returns 502 (Bad Gateway) error codes, and I see error messages like this in the logs:

connect() to unix:/path/to/socket/puma.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client...

It only happens when connecting Nginx and Puma using Unix Sockets and under heavy load (300 new connections per second). I have tried setting the backlog to 1024 in the configuration file:

bind 'unix:///tmp/run/puma.sock?backlog=1024'

And I have also tried to leave it empty, which should default the value to 1024 as well, but nothing works.

Any idea?

@himberjack
Copy link

Any news regarding the 5xx error on load?

@nkokkos
Copy link

nkokkos commented Mar 26, 2019

I believe the behaviour is influenced by the linux kernel parameters too. I had the same problem but I was able to resolve it as follows:

I set bind 'unix:///tmp/run/puma.sock?backlog=1024' as instructed

I took a look at this example: https://easyengine.io/tutorials/linux/sysctl-conf and changed the default somaxconn from 128 to 4096.

You can see the current somaxconn with cat /proc/sys/net/core/somaxconn

I also used https://github.com/wg/wrk to load test my demo app

Used the default example wrk -t12 -c400 -d30s http://127.0.0.1:3000/

For starters, I ran only one puma worker behind nginx; the response was very slow but I got no errors in /var/logs/nginx/error.log

References:
http://www.tweaked.io/guide/kernel/
https://easyengine.io/tutorials/linux/sysctl-conf
https://gist.github.com/perusio/2154235
https://easyengine.io/tutorials/linux/sysctl-conf

@microweb10
Copy link

microweb10 commented Feb 6, 2020

Hi @ernestojpg I'm kinda facing the same issue, and the solution of nkokkos doesn't work for me. I guess there's something else involved (linux kernel settings, linux networking settings...) that I didn't find out yet. Did you resolve your issue? If you did, could you share how? 🙏 Thanks ☺️

@arpu
Copy link

arpu commented Feb 14, 2022

any more infos on this? when i set worker to 1 no error with worker 2 i get the same errors any idea how to debug this more?

@julienbfabre
Copy link

Same issue here, adding ?backlog=1024 didn't help, any ideas?

@nkokkos
Copy link

nkokkos commented May 19, 2023

There seems to be similar problem here: https://gitlab.com/gitlab-org/omnibus-gitlab/-/issues/5752

From what I read here: https://gitlab.com/gitlab-org/omnibus-gitlab/-/issues/5752, it is resolved by setting somaxconn to puma default backlog. So if you set the same number to both somaxconn and backlog, you should be ok?

Try this and see if it works:

echo 1024 > /proc/sys/net/core/somaxconn

stop your puma server

set bind 'unix:///tmp/run/puma.sock?backlog=1024' in puma.rb

start your puma server

See this too: https://gitlab.com/gitlab-org/omnibus-gitlab/-/merge_requests/4688 :
set net.core.somaxconn kernel parameter to a value equal or higher than the default Puma backlog_socket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants