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

debugging deadlocked threads? #1873

Closed
matti opened this issue Jul 30, 2019 · 9 comments
Closed

debugging deadlocked threads? #1873

matti opened this issue Jul 30, 2019 · 9 comments

Comments

@matti
Copy link

matti commented Jul 30, 2019

I have a rails app which I'm able to deadlock by making requests when puma is starting the workers/threads.

The only way it never deadlocks is by having:

workers 1
threads 1, 1

But when it is set to:

workers 1
threads 4, 16

Then most of the time from pumactl stats I can see that the number of running threads goes up and pool_capacity goes down to 1. With curl -v I can see that connection is opened, but no data is received and nothing is seen in the rails app logs.

How do I debug further?

@matti
Copy link
Author

matti commented Jul 30, 2019

I'm running rails 6 and 2.6.3 ruby. Found #1744 (comment) - so if for example ruby 2.6.3 had some issues, how would I be able to confirm this?

@nateberkopec
Copy link
Member

See #1865 (comment)

@matti
Copy link
Author

matti commented Jul 30, 2019

@nateberkopec hmm, I don't have any log lines, so not any ThreadError (deadlock; recursive locking) messages etc.

I did however insert the middleware and http://localhost:3000/rails/locks behaves like the app - no response, the request just hangs.

I'm suspecting that there might be something in Ruby/Puma that causes this, because it only triggers on "every 3rd try".

The app sits behind nginx and I'm running this kind of request generation while booting the app, it seems to make the hang happen more often:

while true; do
   curl localhost:3000 &
   sleep 0.01
done

@matti
Copy link
Author

matti commented Jul 30, 2019

I'm trying to create a repro with a new rails app, but any pointers how I could debug further in my existing app would be great!

@nateberkopec
Copy link
Member

Are you using SSL?

@matti
Copy link
Author

matti commented Jul 31, 2019

Nope - everything is http. I am running this in minikube so it is behind ingress-nginx, but no ssl/https involved. And with curl verbose mode I can see that it opens the http connection, but writes no data - and no lines in rails log after listening 0.0.0.0:3000

and it never hangs with threads 1,1 and sometimes does not hang with threads 4,16 so that makes me suspect that ruby/puma has some deadlock and not rails.

@nateberkopec
Copy link
Member

and it never hangs with threads 1,1 and sometimes does not hang with threads 4,16 so that makes me suspect that ruby/puma has some deadlock and not rails.

That's not necessarily true. You probably just have a deadlock in your app that isn't revealed unless you're running multi-threaded.

@matti
Copy link
Author

matti commented Jul 31, 2019

Yeah you are right - I just can't find any clues anywhere (no log messages etc)

Can I somehow see Puma's threads what they are doing? Like with some software you can send -TTIN signal and get debug output?

@nateberkopec
Copy link
Member

Try applying #1320

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

No branches or pull requests

2 participants