Luiz E.
Luiz E.

Reputation: 7249

how to debug to find the code that is blocking the main thread

I have a Rails app running version 6.1.1 and currently, we use Ruby 2.7.2

While trying to upgrade to Ruby 3, I'm facing an interesting issue: some code apparently is blocking the main thread. When I try to boot the server or run the tests, the console stuck and I can't even stop the process, I have to kill it.

I tracked it down to one gem called valvat, used to validate EU VAT numbers. I opened an issue on its Github repo but the maintainer couldn't reproduce even using the same Gemfile.lock I have, which lead me to believe that it might not be just the gem, gotta be something else in my code.

This is what happens when I try to boot the server:

=> Booting Puma
=> Rails 6.1.1 application starting in development
=> Run `bin/rails server --help` for more startup options
^C^C^C

as one can see, I can't even stop it, the thread is now hanging and I can't tell exactly by whom.

I tried to run the specs with -b -w to see what I can see but got the same error: the thread hangs and the warnings I get from Ruby are just generic ones like method already defined or something like that.

This is the last output from the console while running specs with -b -w before the thread hangs:

/Users/luiz/rails_dev/app/config/initializers/logging_rails.rb:18: warning: method redefined; discarding old tag_logger
/Users/luiz/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/activejob-6.1.1/lib/active_job/logging.rb:19: warning: previous definition of tag_logger was here

thing is, I also get these warnings when I remove the gem and run this command though the specs run without issues then.

Is there a way to track this down to whatever is causing the thread to hang?

Upvotes: 0

Views: 306

Answers (1)

Benjamin Bouchet
Benjamin Bouchet

Reputation: 13181

If you have no error message, it's hard to understand where exactly your application hangs.

As the developer cannot reproduce with your Gemfile.lock, it's possible that one of your config file or initializers is the culprit. You could create a new blank application with the same Gemfile, add your config and initializers files one by one, and test each time if the server runs until you find which one is causing the freeze.

Test also your application with another Ruby version (are you using rbenv or RVM?)

Also check your syslog, as valvat calls a web service you may find connection errors there. Check this doc on how to access your syslog: https://www.howtogeek.com/356942/how-to-view-the-system-log-on-a-mac/

Upvotes: 1

Related Questions