Re: [NWRUG] Help With Some Puma Warnings

2024-01-25 Thread Will Jessop
I highly recommend installing direnv (https://direnv.net/, available in 
homebrew) instead of using the dotenv gem and .env files. I've seen the sort of 
confusion you have had /repeatedly/ over the years with dotenv as it doesn't 
actually provide an environment at all, it's mis-named. direnv actually 
provides a first-class environment to your application so any command you run 
is in that env from program start:

will@lentil ~/www/oas/master (on 1e5da09)% cat .envrc 
export REDIS_URL=redis://localhost:6379
export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
export RUBYOPT=-w
# Temporary for segfault https://github.com/ged/ruby-pg/issues/538
export PGGSSENCMODE="disable"
will@lentil ~/www/oas/master (on 1e5da09)% env | grep RUBYOPT
RUBYOPT=-w

> On 25 Jan 2024, at 17:36, 'Rob Whittaker' via North West Ruby User Group 
> (NWRUG)  wrote:
> 
> Thank you both for your comments.
> 
> Much of what Lee said went over my head and made me realise how little I know 
> about Puma. I have always accepted that it's the tool to use since it gained 
> popularity. Some stuff went in, but now I want to learn more.
> 
> After Tekin's comments about rails s, I did some more investigating and was 
> wrong. Running rails s produces no warnings. Running bundle exec puma as per 
> the Procfile gives warnings, though.
> 
> Puma loads the config/puma.rb file by default. I combed through that file and 
> commented out lines until the warnings disappeared. The offending line has 
> something to do with workers. If I set the value to zero, then the warnings 
> disappear.
> 
> I set the number of workers from environment variables. When we have no value 
> set, it defaults to two workers. I have this value set to zero in my .env 
> file. I thought it might be that I was using 0, and the environment saw this 
> as no value set. I tried setting it to "0", but still no dice. It was time 
> for a trusty raise. No matter what value I put in .env, there was nothing in 
> my error. Weird.
> 
> Then, I found this question on Stack Overflow. It makes sense that we load 
> dotenv after Puma. The gem is part of the Rails stack, after all. What could 
> I do?
> 
> My next step was to create a separate Procfile.dev with the following line 
> and a bin/dev wrapper.
> 
> 
> web: WEB_CONCURRENCY=0 bundle exec puma -p $PORT -C ./config/puma.rb
> 
> 
> This approach seems like it could be better. I'll have to duplicate the 
> commands between my two files and now use bin/dev to start my server. With 
> the extra information I've provided, can anybody give a better solution?

-- 
You received this message because you are subscribed to the Google Groups 
"North West Ruby User Group (NWRUG)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to nwrug-members+unsubscr...@googlegroups.com.
To view this discussion on the web, visit 
https://groups.google.com/d/msgid/nwrug-members/52EC2A42-D20F-4AD7-A64B-E3FBBA52440D%40willj.net.


Re: [NWRUG] Help With Some Puma Warnings

2024-01-25 Thread 'Rob Whittaker' via North West Ruby User Group (NWRUG)


Thank you both for your comments.


Much of what Lee said went over my head and made me realise how little I 
know about Puma. I have always accepted that it's the tool to use since it 
gained popularity. Some stuff went in, but now I want to learn more.


After Tekin's comments about rails s, I did some more investigating and was 
wrong. Running rails s produces no warnings. Running bundle exec puma as 
per the Procfile gives warnings, though.


Puma loads the config/puma.rb file by default. I combed through that file 
and commented out lines until the warnings disappeared. The offending line 

 
has something to do with workers. If I set the value to zero, then the 
warnings disappear.


I set the number of workers from environment variables. When we have no 
value set, it defaults to two workers. I have this value set to zero in my 
.env file. I thought it might be that I was using 0, and the environment 
saw this as no value set. I tried setting it to "0", but still no dice. It 
was time for a trusty raise. No matter what value I put in .env, there was 
nothing in my error. Weird.


Then, I found this question on Stack Overflow 
. It makes sense that we load dotenv 
after Puma. The gem is part of the Rails stack, after all. What could I do?


My next step was to create a separate Procfile.dev with the following line 
and a bin/dev wrapper.



web: WEB_CONCURRENCY=0 bundle exec puma -p $PORT -C ./config/puma.rb



This approach seems like it could be better. I'll have to duplicate the 
commands between my two files and now use bin/dev to start my server. With 
the extra information I've provided, can anybody give a better solution?

On Wednesday, January 24, 2024 at 10:11:42 AM UTC Tekin Suleyman wrote:

>
> On 24 Jan 2024, at 06:34, 'Rob Whittaker' via North West Ruby User Group 
> (NWRUG)  wrote:
>
> Hey, everybody!
>
> I have a side project of getting my first proper Rails app 
>  up to date. The last time I 
> touched the project was about six years ago. Ruby, Rails, and all the other 
> gems are out of date. I'm trying to be sensible and "safe" in my approach 
> to each upgrade. This is more of an exercise in approach than anything 
> else. The repo is public for folks who want to have a look.
>
> After a chat with Will at the previous NWRUG, I decided to fix any 
> warnings before moving on. This is a sensible and logical plan. The latest 
> thing on my list is this list of warnings from Puma.
>
> 07:33:22 web.1  |  [25567] ! WARNING: Detected 5 Thread(s) started in 
> app boot:
> 07:33:22 web.1  |  [25567] ! 
> #  
> sleep> - 
> /Users/purinkle/.asdf/installs/ruby/2.5.9/lib/ruby/gems/2.5.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:302:in
>  
> `sleep'
> 07:33:22 web.1  |  [25567] ! 
> #  
> sleep_forever> - 
> /Users/purinkle/.asdf/installs/ruby/2.5.9/lib/ruby/2.5.0/forwardable.rb:229:in
>  
> `pop'
> 07:33:22 web.1  |  [25567] ! 
> #  
> sleep> - 
> /Users/purinkle/.asdf/installs/ruby/2.5.9/lib/ruby/gems/2.5.0/gems/rb-fsevent-0.11.2/lib/rb-fsevent/fsevent.rb:44:in
>  
> `select'
> 07:33:22 web.1  |  [25567] ! 
> #  
> sleep> - 
> /Users/purinkle/.asdf/installs/ruby/2.5.9/lib/ruby/gems/2.5.0/gems/listen-3.8.0/lib/listen/record/entry.rb:44:in
>  
> `realpath'
> 07:33:22 web.1  |  [25567] ! 
> #  
> sleep_forever> - 
> /Users/purinkle/.asdf/installs/ruby/2.5.9/lib/ruby/2.5.0/forwardable.rb:229:in
>  
> `pop'
>
> I only see these warnings when I start the server using heroku local. If 
> I start the server using rails s, then everything is okay.
>
> There is no pressure here; I want to use this repo as a learning space. I 
> want to understand the problem more than anything else. Is this something 
> that I can fix? Is it something that a future gem bump will fix? How would 
> you approach debugging this problem?
>
>
> I wouldn’t worry too much about this. Puma warns about threads that are 
> spawned during app boot and before it forks workers as those threads can be 
> unsafe/lead to issues, but the threads listed are almost all from the 
> listen gem, which is a development dependency, and I can't imagine 
> ActiveRecord will be spawning threads that are not safe for forking. I 
> wouldn’t be surprised if the issue goes away when you update dependencies.
>
> It’s interesting that you don’t see the same warnings with `rails server`. 
> Is it actually booting using Puma and not another web server?
>
> Tekin
>
>
>
> —Rob
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "North West Ruby User Group (NWRUG)" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to nwrug-member...@googlegroups.com.
> To view this discussion on the web, visit 
>