I'm trying to make a little library that wraps over march_hare and is used as part of our Rails app. It needs to connect on app startup and disconnect on shutdown.
I'am aiming to something similar to the ruby-kafka Rails integration via initializer:
configure my service
run it
specify shutdown procedure
The problem is my at_exit blocks are sometimes not executed. What may be the cause of this issue? Is there a way to fix it and ensure my at_exit blocks are called?
Investigating the issue, I created a blank demo app with the following initializer:
class SomeClass
def self.shutdown(reason)
msg = "#{Time.now} SHUTDOWN via #{reason}!"
puts msg
open('log/development.log', 'a') do |f|
f.puts msg
end
end
end
at_exit { SomeClass.shutdown(:at_exit1) }
at_exit { SomeClass.shutdown(:at_exit2) }
at_exit { SomeClass.shutdown(:at_exit3) }
puts "#{Time.now} INITIALIZED!"
In 9 out of 10 run + terminate cycles I get:
$ rails s
=> Booting Puma
=> Rails 4.2.7.1 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
2017-05-22 15:29:16 +0300 INITIALIZED!
Puma starting in single mode...
* Version 3.4.0 (jruby 9.1.2.0 - ruby 2.3.0), codename: Owl Bowl Brawl
* Min threads: 0, max threads: 16
* Environment: development
* Listening on tcp://localhost:3000
Use Ctrl-C to stop
^C- Gracefully stopping, waiting for requests to finish
Exiting
=== puma shutdown: 2017-05-22 15:29:30 +0300 ===
- Goodbye!
2017-05-22 15:29:30 +0300 SHUTDOWN via at_exit3!
2017-05-22 15:29:30 +0300 SHUTDOWN via at_exit2!
2017-05-22 15:29:30 +0300 SHUTDOWN via at_exit1!
But once in a while the result is:
$ rails s
=> Booting Puma
=> Rails 4.2.7.1 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
2017-05-22 15:29:45 +0300 INITIALIZED!
Puma starting in single mode...
* Version 3.4.0 (jruby 9.1.2.0 - ruby 2.3.0), codename: Owl Bowl Brawl
* Min threads: 0, max threads: 16
* Environment: development
* Listening on tcp://localhost:3000
Use Ctrl-C to stop
^C- Gracefully stopping, waiting for requests to finish
Exiting
=== puma shutdown: 2017-05-22 15:30:17 +0300 ===
- Goodbye!
2017-05-22 15:30:17 +0300 SHUTDOWN via at_exit2!
2017-05-22 15:30:17 +0300 SHUTDOWN via at_exit1!
My Gemfile has only gem 'puma' added.
Ruby version: jruby 9.1.2.0
Rails version: Rails 4.2.7.1
System Version: macOS 10.12.4
This is something to do with JRuby. You could try upgrading JRuby to the latest version and see if that's fixed.
Else follow this thread for more reference.
https://github.com/jruby/jruby/issues/5437
Related
I have been working on a rails application for the past four months. Suddenly one-day puma server stops responding to the requests.
Here is what I see in the terminal:
$ rails s
=> Booting Puma
=> Rails 5.1.7 application starting in development
=> Run `rails server -h` for more startup options
Puma starting in single mode...
Puma version: 5.5.2 (ruby 2.6.3-p62) ("Zawgyi")
Min threads: 5
Max threads: 5
Environment: development
PID: 12446
Listening on http://127.0.0.1:3000
Listening on http://[::1]:3000
Use Ctrl-C to stop
Started GET "/" for ::1 at 2021-11-10 12:28:58 +0530
Started GET "/recommendations" for ::1 at 2021-11-10 12:29:20 +0530
Started GET "/" for ::1 at 2021-11-10 12:29:39 +0530
Started GET "/" for ::1 at 2021-11-10 12:29:40 +0530
I tried many things like changing the port, making sure that the rails version in my local and gemfile are the same, trying with other ruby versions, uninstalling and reinstalling ruby and rails in local.
Tried keeping binding.pry in the application controller's index action but that not getting hit. I am not able to exit from that point, the server gets stuck there. There are no recent changes in my application.
Can anyone suggest to me what might be the problem?
I'm using rails5.2. For testing i've created below controller.
class IndexController < ApplicationController
def index
sleep(10)
render text: "done"
end
end
If I make 5 parallel requests, 1st request takes 10s, 2nd takes 20s, 3rd takes 30s and so on..
myAppRails5 aravind$ bin/rails server
=> Booting Puma
=> Rails 5.2.0 application starting in development
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.11.4 (ruby 2.5.1-p57), codename: Love Song
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop
Puma configuration : Min threads: 5, max threads: 5
Rails 5.2.0 application starting in development
development.rb
puma.rb
As per puma doc, threaded is supported. How do I achieve multi threading here?
rails server
=> Booting Puma
=> Rails 5.2.0 application starting in development
=> Run rails server -h for more startup options
[44266] Puma starting in cluster mode...
[44266] * Version 3.6.2 (ruby 2.5.1-p57), codename: Sleepy Sunday Serenity
[44266] * Min threads: 5, max threads: 5
[44266] * Environment: development
[44266] * Process workers: 1
[44266] * Preloading application
[44266] * Listening on tcp://localhost:3000
[44266] Use Ctrl-C to stop
[44266] - Worker 0 (pid: 44286) booted, phase: 0
^C[44266] - Gracefully shutting down workers...
[44266] === puma shutdown: 2018-06-12 14:28:53 -0500 ===
[44266] - Goodbye!
Exiting
went to http://www.localhost3000.org/
says you forgot to start your server
Running
Rails 5.2.0
Postgesql 9.6
It looks like http://www.localhost3000.org/ is a website that someone bought to help you when you mistype your attempt to get to your localhost. It's not your own server responding
As the website suggests, try to go instead to http://localhost:3000
Use this address localhost:3000. The link you included is a live website someone has published as a reminder to start your server.
Use this address http://localhost:3000 but you can still edit your url, follow this article: Edit localhost
I want to run Rails application on EC2 machine. When my SSH session terminates the rails server shutdown. I want to run the rails server in the background. I used rails s -d command to run rails daemon mode.
But it seems like Puma is not started. This is the message I receive and after that process terminates.
Booting Puma
=> Rails 5.0.6 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
Usually when I run rails server I get
=> Booting Puma
=> Rails 5.0.6 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.11.0 (ruby 2.3.5-p376), codename: Love Song
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop
What is going wrong? Is puma server booting up but not starting?
I am deploying a Rails application into production using Thin. Right after starting rails, Thin shuts down, the only ouput is 'Exiting':
$ bundle exec rails s -e production
=> Booting Thin
=> Rails 4.0.0 application starting in production on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
>> Thin web server (v1.5.1 codename Straight Razor)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:3000, CTRL+C to stop
Exiting
The same configuration / setup works in development. The same configuration works for production using WEBrick:
$ bundle exec rails s -e production
=> Booting WEBrick
=> Rails 4.0.0 application starting in production on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2013-07-19 17:59:07] INFO WEBrick 1.3.1
[2013-07-19 17:59:07] INFO ruby 2.0.0 (2013-06-27) [x86_64-linux]
[2013-07-19 17:59:07] INFO WEBrick::HTTPServer#start: pid=5231 port=3000
Surely it should be possible to receive some output on why it is shutting down from a web server rated for production use. However, I have not found out how.
Any ideas?
Turns out starting Thin in production mode made Rails eager load a module also using EventMachine, thus keeping the Thin code from being blocked after starting and immediately shutting down instead.