puma server is not starting in SSL mode - ruby-on-rails

I am starting puma server like below
puma -b ssl://sstp.localhost.domain.com:7000?key=/private/etc/apache2/ssl/sstp.localhost.domain.com.key&cert=/private/etc/apache2/ssl/sstp.localhost.domain.com.crt
but it is serving content only in http mode.
on requesting
https://sstp.localhost.domain.com:7000/path/file.js
I get the error
This site can’t provide a secure connection
sstp.localhost.domain.com sent an invalid response.
ERR_SSL_PROTOCOL_ERROR
I have used open ssl to self sign the certificate
I am using puma 1.6.3 as recommended.I was using 2.8 earlier, downgraded now as recommended by this thread https://github.com/puma/puma/issues/350
I am using google chrome browser, the response is same on every browser
Note: I use ramaze a framework for mocking purpose (http://ramaze.net/), Ramaze starts Webrick in port 7000 hence am tied to use port 7000
The logs read like below
$ puma
W [2016-09-01 10:22:56 $2082] WARN | : No explicit root folder found, assuming it is /Users/<username>/path/mock-server
D [2016-09-01 10:22:56 $2082] DEBUG | : Using webrick
I [2016-09-01 10:22:56 $2082] INFO | : WEBrick 1.3.1
I [2016-09-01 10:22:56 $2082] INFO | : ruby 2.1.1 (2014-02-24) [x86_64-darwin12.0]
D [2016-09-01 10:22:56 $2082] DEBUG | : Rack::Handler::WEBrick is mounted on /.
I [2016-09-01 10:22:56 $2082] INFO | : WEBrick::HTTPServer#start: pid=2082 port=7000
D [2016-09-01 10:23:04 $2082] DEBUG | : accept: 127.0.0.1:50218
D [2016-09-01 10:23:04 $2082] DEBUG | : accept: 127.0.0.1:50217
E [2016-09-01 10:23:04 $2082] ERROR | : bad URI `?\x13?'.
E [2016-09-01 10:23:04 $2082] ERROR | : bad URI `?\x13?'.
localhost - - [01/Sep/2016:10:23:04 BST] "\x16\x03\x01\x00?\x01\x00\x00?\x03\x03?T?e\x1D?6?\x04?C??\x16???\x06!Vjm??\x1AW&p(??\x04\x00\x00"?+?/?,?0̨̩?\x14?\x13?\t?\x13?" 400 290
- -> ?\x13?
D [2016-09-01 10:23:04 $2082] DEBUG | : close: 127.0.0.1:50217
localhost - - [01/Sep/2016:10:23:04 BST] "\x16\x03\x01\x00?\x01\x00\x00?\x03\x03?Pi'Zߑ\x04!/?\x13m??#?M?f?)?4?d??4$١\x00\x00"?+?/?,?0̨̩?\x14?\x13?\t?\x13?" 400 290
- -> ?\x13?
D [2016-09-01 10:23:04 $2082] DEBUG | : close: 127.0.0.1:50218
D [2016-09-01 10:23:07 $2082] DEBUG | : accept: 127.0.0.1:50220
D [2016-09-01 10:23:07 $2082] DEBUG | : accept: 127.0.0.1:50221
E [2016-09-01 10:23:07 $2082] ERROR | : bad Request-Line `\x16\x03\x01\x00?\x01\x00\x00?\x03\x03?yiS\x7Ff??݄[???3I-Z\a\t?L??>C?Ŧ???\x00\x00"?+?/?,?0̨̩?\x14?\x13?\t?\x13?'.
E [2016-09-01 10:23:07 $2082] ERROR | : bad URI `?\x13?'.
localhost - - [01/Sep/2016:10:23:07 BST] "\x16\x03\x01\x00?\x01\x00\x00?\x03\x03P1?\x00V?0?r???y/??:;???҈y?s?c?G\x17?\x00\x00"?+?/?,?0̨̩?\x14?\x13?\t?\x13?" 400 290
- -> ?\x13?

Related

Why is the VSCode remote debug session not engaged when code is run at a breakpoint in Ruby on Rails?

I’m using VSCode 1.61.1 on Mac Big Sur with a Rails 4.2 application (ruby-debug-ide 0.7.3, debase 0.2.2.beta10), running with a Unicorn app server. The Rails app runs on a virtual server (built through Vagrant). I have exposed all the necessary ports. I have this configured in my launch.json
"configurations": [
{
"name": "Listen for rdebug-ide",
"type": "Ruby",
"request": "attach",
"cwd": "${workspaceRoot}",
"remoteHost": "127.0.0.1",
"remotePort": "1234",
"remoteWorkspaceRoot": "/home/my-app",
"showDebuggerOutput": true
},
Then in my virtual server, I start Rails using
rdebug-ide --debug --host 0.0.0.0 --port 1234 -- bin/rails s -p 3000 -b 0.0.0.0
From VS Code, I then attach the debugger by clicking on
On my Rails server, I can see this debug output
15:08:31 rails.1 | Connected from local client
15:08:31 rails.1 | 5360: Starting control thread
15:08:31 rails.1 | 5360: Processing in control: start
15:08:31 rails.1 | 5360: Starting: running program script
15:08:31 rails.1 | 5360: Processing in control: thread list
15:08:31 rails.1 | 5360: <threads>
15:08:31 rails.1 | 5360: <thread id="1" status="sleep" pid="5360" />
15:08:31 rails.1 | 5360: </threads>
15:08:39 rails.1 | => Booting Unicorn
15:08:39 rails.1 | => Rails 4.2.10 application starting in development on http://0.0.0.0:3000
15:08:39 rails.1 | => Run `rails server -h` for more startup options
15:08:39 rails.1 | => Ctrl-C to shutdown server
15:08:39 rails.1 | W, [2021-10-18T15:08:39.643324 #5360] WARN -- ddtrace: [ddtrace] Unable to patch Datadog::Contrib::Faraday::Integration (Available?: true, Loaded? true, Compatible? false, Patchable? false)
15:08:41 rails.1 | I, [2021-10-18T15:08:41.538531 #5360] INFO -- : unlinking existing socket=/home/my-app/tmp/sockets/unicorn.sock
15:08:41 rails.1 | I, [2021-10-18T15:08:41.538665 #5360] INFO -- : listening on addr=/home/my-app/tmp/sockets/unicorn.sock fd=14
15:08:41 rails.1 | I, [2021-10-18T15:08:41.538782 #5360] INFO -- : listening on addr=0.0.0.0:3000 fd=15
15:08:41 rails.1 | Disconnected from Redis
15:08:41 rails.1 | I, [2021-10-18T15:08:41.544540 #5360] INFO -- : master process ready
15:08:41 rails.1 | Connected to Redis
15:08:41 rails.1 | I, [2021-10-18T15:08:41.551381 #6487] INFO -- : worker=0 ready
Then from VSCode, when I add a breakpoint, I see this output on my Rails app
15:09:16 rails.1 | 5360: Processing in control: break /home/my-app/app/controllers/api/v1/products_controller.rb:10
15:09:16 rails.1 | 5360: <breakpointAdded no="1" location="/home/my-app/app/controllers/api/v1/products_controller.rb:10"/>
But then when I actually visit the web page that is supposed to hit the breakpoint, nothing happens. I now the code is called because I see “print” statements output to the log. But not sure what else I need to do to get VSCode’s debugger to engage at the appropriate breakpoint.
Please refer to this answer.
How to use ruby-debug-ide with unicorn_rails?
When using Unicorn you need to provide --dispatcher-port option.

rails 4.2 can't see db queries in heroku logs even though log_level set to :debug

Here is a project I'm working on: https://github.com/homanchou/the_drawing_challenge
I'm having trouble seeing any db queries in the server logs on heroku or even locally in the terminal when running Puma with Foreman.
All I see are asset or web requests
21:54:34 web.1 | started with pid 54784
21:54:35 web.1 | [54784] Puma starting in cluster mode...
21:54:35 web.1 | [54784] * Version 2.10.2 (ruby 2.1.5-p273), codename: Robots on Comets
21:54:35 web.1 | [54784] * Min threads: 1, max threads: 4
21:54:35 web.1 | [54784] * Environment: development
21:54:35 web.1 | [54784] * Process workers: 2
21:54:35 web.1 | [54784] * Preloading application
21:54:36 web.1 | [54784] * Listening on tcp://0.0.0.0:5000
21:54:36 web.1 | [54784] Use Ctrl-C to stop
21:54:36 web.1 | [54784] - Worker 0 (pid: 54785) booted, phase: 0
21:54:36 web.1 | [54784] - Worker 1 (pid: 54786) booted, phase: 0
21:54:43 web.1 | [54785] 127.0.0.1 - - [02/Apr/2015:21:54:43 -0700] "GET / HTTP/1.1" 200 - 0.3120
21:54:43 web.1 | [54785] 127.0.0.1 - - [02/Apr/2015:21:54:43 -0700] "GET /logo_header.png HTTP/1.1" 304 - 0.0079
21:54:45 web.1 | [54785] 127.0.0.1 - - [02/Apr/2015:21:54:45 -0700] "GET /challenges/8 HTTP/1.1" 200 - 0.0443
21:54:45 web.1 | [54785] 127.0.0.1 - - [02/Apr/2015:21:54:45 -0700] "GET /logo_header.png HTTP/1.1" 304 - 0.0067
I had to add another line to the Procfile log: tail -f -n 0 log/development.log to see logs or errors in stdout of foreman start like I normally do, but that only works locally and not on heroku unless I want to scale up a process for that tailing.
In my other rails project I can see the db queries fine, even on heroku I can see the db queries in the log:
2015-04-03T03:46:40.052067+00:00 app[web.1]: Started GET "/api/notifications/unread_count" for 97.93.34.8 at 2015-04-03 03:46:40 +0000
2015-04-03T03:46:40.070865+00:00 app[web.1]: Merchant Load (2.7ms) SELECT "merchants".* FROM "merchants" WHERE "merchants"."id" = $1 ORDER BY "merchants"."id" ASC LIMIT 1 [["id", 7502]]
2015-04-03T03:46:40.085454+00:00 app[web.1]: SQL (2.3ms) UPDATE "merchants" SET "updated_at" = '2015-04-03 03:46:40.074442', "last_active_at" = '2015-04-03 03:46:40.074442' WHERE "merchants"."id" = $1 [["id", 7502]]
2015-04-03T03:46:40.101382+00:00 app[web.1]: (2.3ms) SELECT COUNT(*) FROM "notifications" WHERE "notifications"."merchant_id" = $1 AND "notifications"."state" = $2 [["merchant_id", 7502], ["state", "unread"]]
2015-04-03T03:46:40.058083+00:00 app[web.1]: Processing by NotificationsController#unread_count as JSON
2015-04-03T03:46:40.073916+00:00 app[web.1]: (1.0ms) BEGIN
2015-04-03T03:46:40.093737+00:00 app[web.1]: (7.4ms) COMMIT
2015-04-03T03:46:40.102858+00:00 app[web.1]: Completed 200 OK in 45ms (Views: 0.2ms | ActiveRecord: 15.6ms)
I tried comparing the two and even copying over some environment configurations but I still can't figure it out. I've tried setting config.log_level = :debug on the production environment. I can see db queries in the ruby console, but not the heroku or local puma stdout in the terminal. What am I missing?
If you need to use puma for websockets etc try adding
ActiveRecord::Base.logger.level = Logger::DEBUG
to your environments.rb or environments/production

Log output too verbose - how to change log level?

I'm trying to debug my simple Rails app and find navigating and printing with puts works well but the log in Bash is way too verbose. I've looked through lots of questions/responses here and have tried some of them but without success. I tried importing the quiet_assets Gem with
gem 'quiet_assets', group: :development
and have tried changing log levels to :error in production.rb
config.log_level = Logger::error
But I still get all the GET requests of Assets when navigating making review of logs difficult.
Worth noting I've tried restarting the server and ran bundle just in case. I did hard refresh even though browser cache shouldn't have anything to do with this.
Here's example navigation:
20:08:55 web.1 | 127.0.0.1 - - [22/Oct/2014 20:08:55] "GET /application.js HTTP/1.1" 304 - 0.0185
20:08:55 web.1 | 127.0.0.1 - - [22/Oct/2014 20:08:55] "GET /application.css HTTP/1.1" 304 - 0.0790
20:08:56 web.1 | 127.0.0.1 - - [22/Oct/2014 20:08:56] "GET /brands/46 HTTP/1.1" 304 - 0.0111
20:08:56 web.1 | 127.0.0.1 - - [22/Oct/2014 20:08:56] "GET /application.js HTTP/1.1" 304 - 0.0062
20:08:56 web.1 | 127.0.0.1 - - [22/Oct/2014 20:08:56] "GET /application.css HTTP/1.1" 304 - 0.0066
20:08:57 web.1 | 127.0.0.1 - - [22/Oct/2014 20:08:57] "GET /brands/46 HTTP/1.1" 304 - 0.0105
20:08:57 web.1 | 127.0.0.1 - - [22/Oct/2014 20:08:57] "GET /application.js HTTP/1.1" 304 - 0.0056
20:08:57 web.1 | 127.0.0.1 - - [22/Oct/2014 20:08:57] "GET /application.css HTTP/1.1" 304 - 0.0063
20:09:13 web.1 | E, [2014-10-22T20:09:13.695412 #5880] ERROR -- : worker=0 PID:5916 timeout (16s > 15s), killing
20:09:13 web.1 | E, [2014-10-22T20:09:13.704183 #5880] ERROR -- : reaped #<Process::Status: pid 5916 SIGKILL (signal 9)> worker=0
20:09:13 web.1 | I, [2014-10-22T20:09:13.710805 #5923] INFO -- : worker=0 ready
It seems you are seeing production log, are you? if that is the case quiet_assets should be included in production too.
gem 'quiet_assets'

How to debug Ruby On Rails on AWS OpsWorks?

After Serval days testing for how to deploy my ROR project on AWS EC2.
Rubber,eb,at last I decided to use OPSWORKS because of a video in youtube.
But the deployment still hard.
OK,My question is:How to debug Ruby On Rails on AWS OpsWorks?
I've know
In the web console,we can get deploy log.
Via ssh,we can get [apptest].access.log,error.log,access.log in the path
/var/log/nginx/(I test with nginx and Unicorn)
But all of below is log about deployment,and few logs/infos about access website.
For example:(test.access.log)
133.255.255.124 - - [25/Jun/2014:15:10:03 +0000] "GET / HTTP/1.1" 500 5 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.76.4 (KHTML, like Gecko) Version/7.0.4 Safari/537.76.4"
133.255.255.124 - - [25/Jun/2014:15:10:19 +0000] "GET / HTTP/1.1" 500 5 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.76.4 (KHTML, like Gecko) Version/7.0.4 Safari/537.76.4"
while I got 500 .where can I found detail about this information?
Here is error.log in nginx
1. 2014/06/25 13:35:59 [emerg] 5502#0: still could not bind()
2. 2014/06/25 15:23:06 [crit] 11593#0: *2 connect() to
unix:/srv/www/test/shared/sockets/unicorn.sock failed (2: No such
file or directory) while connecting to upstream, client:
133.255.255.124, server: test, request: "GET / HTTP/1.1", upstream: "http://unix:/srv/www/test/shared/sockets/unicorn.sock:/", host:
"55.218.118.37"
you can find during 500 return ,error.log info is useless,and access.log is nothing to show.
Where Can I get detail Debug info while visit test website,like tomcat server
Thanks a lot.
Here is something in unicorn.stderr.log,and production.log unicorn.stdout.log
is nothing to show.even I set config.log_level = :debug in production.rb and restart the web server.
I, [2014-06-25T23:45:18.172877 #6436] INFO -- : executing ["/home/deploy/.bundler/test/ruby/2.0.0/bin/unicorn_rails", "--env", "production", "--daemonize", "-c", "/srv/www/test/shared/config/unicorn.conf", {10=>#<Kgio::UNIXServer:fd 10>}] (in /srv/www/test/releases/20140625234506)
I, [2014-06-25T23:45:19.196006 #6436] INFO -- : inherited addr=/srv/www/test/shared/sockets/unicorn.sock fd=10
I, [2014-06-25T23:45:19.196505 #6436] INFO -- : Refreshing Gem list
I, [2014-06-25T23:45:23.769647 #6449] INFO -- : worker=0 ready
I, [2014-06-25T23:45:23.811102 #6436] INFO -- : master process ready
I, [2014-06-25T23:45:23.848092 #6452] INFO -- : worker=1 ready
I, [2014-06-25T23:45:24.129596 #5830] INFO -- : reaped #<Process::Status: pid 5852 exit 0> worker=0
I, [2014-06-25T23:45:24.129878 #5830] INFO -- : reaped #<Process::Status: pid 5855 exit 0> worker=1
I, [2014-06-25T23:45:24.129967 #5830] INFO -- : master complete
You would need to do something like the following after logging in :
sudo su deploy
cd /srv/www/#{application_name}/shared/log/
The files are stored under :
/srv/www/#{application_name}/shared/log
➜ log ls -lsh *.log
32K -rw-r--r-- 1 deploy www-data 32K Jun 25 20:45 cron-error.log
4.0K -rw-r--r-- 1 deploy www-data 1.6K Jun 25 20:30 cron.log
192K -rw-r--r-- 1 deploy www-data 188K Jun 25 20:45 newrelic_agent.log
48M -rw-r--r-- 1 deploy www-data 47M Jun 25 20:55 staging.log
0 -rw-r--r-- 1 deploy www-data 0 Jun 24 06:46 unicorn.stderr.log
4.0K -rw-r--r-- 1 deploy www-data 3.1K Jun 25 08:49 unicorn.stdout.log
NOTE : #{application_name} is whatever your shortcode is for the application.

How to resolve Rack Lint errors?

I have noticed that certain requests, particularly from Uptime Robot to test page uptime have recently started generated the following Rack Lint error on my Rails 3.1.x app:
21:47:05 web.1 | Started HEAD "/" for 74.86.158.106 at 2012-03-22 21:47:05 -0400
21:47:05 web.1 | Processing by HomeController#index as */*
...
21:47:05 web.1 | /Users/username/.rvm/gems/ruby-1.9.3-p125#project/gems/activesupport-3.1.4/lib/active_support/core_ext/string/output_safety.rb:23: warning: regexp match /.../n against to UTF-8 string
...
21:47:05 web.1 | Completed 200 OK in 81ms (Views: 60.3ms | ActiveRecord: 0.0ms)
21:47:05 web.1 | 74.86.158.106 - - [22/Mar/2012 21:47:05] "GET / HTTP/1.1" 200 31842 0.1993
21:47:05 web.1 | E, [2012-03-22T21:47:05.546848 #18938] ERROR -- : app error: Content-Length header was 31842, but should be 0 (Rack::Lint::LintError)
21:47:05 web.1 | E, [2012-03-22T21:47:05.546978 #18938] ERROR -- : /Users/username/.rvm/gems/ruby-1.9.3-p125#project/gems/rack-1.3.6/lib/rack/lint.rb:19:in `assert'
21:47:05 web.1 | E, [2012-03-22T21:47:05.547079 #18938] ERROR -- : /Users/username/.rvm/gems/ruby-1.9.3-p125#project/gems/rack-1.3.6/lib/rack/lint.rb:501:in `verify_content_length'
21:47:05 web.1 | E, [2012-03-22T21:47:05.547178 #18938] ERROR -- : /Users/username/.rvm/gems/ruby-1.9.3-p125#project/gems/rack-1.3.6/lib/rack/lint.rb:525:in `each'
21:47:05 web.1 | E, [2012-03-22T21:47:05.547277 #18938] ERROR -- : /Users/username/.rvm/gems/ruby-1.9.3-p125#project/gems/rack-1.3.6/lib/rack/body_proxy.rb:23:in `method_missing'
21:47:05 web.1 | E, [2012-03-22T21:47:05.547375 #18938] ERROR -- : /Users/username/.rvm/gems/ruby-1.9.3-p125#project/gems/unicorn-4.2.0/lib/unicorn/http_response.rb:41:in `http_response_write'
21:47:05 web.1 | E, [2012-03-22T21:47:05.547476 #18938] ERROR -- : /Users/username/.rvm/gems/ruby-1.9.3-p125#project/gems/unicorn-4.2.0/lib/unicorn/http_server.rb:538:in `process_client'
21:47:05 web.1 | E, [2012-03-22T21:47:05.547574 #18938] ERROR -- : /Users/username/.rvm/gems/ruby-1.9.3-p125#project/gems/unicorn-4.2.0/lib/unicorn/http_server.rb:604:in `worker_loop'
21:47:05 web.1 | E, [2012-03-22T21:47:05.547672 #18938] ERROR -- : /Users/username/.rvm/gems/ruby-1.9.3-p125#project/gems/unicorn-4.2.0/lib/unicorn/http_server.rb:487:in `spawn_missing_workers'
21:47:05 web.1 | E, [2012-03-22T21:47:05.547770 #18938] ERROR -- : /Users/username/.rvm/gems/ruby-1.9.3-p125#project/gems/unicorn-4.2.0/lib/unicorn/http_server.rb:137:in `start'
21:47:05 web.1 | E, [2012-03-22T21:47:05.547867 #18938] ERROR -- : /Users/username/.rvm/gems/ruby-1.9.3-p125#project/gems/unicorn-4.2.0/bin/unicorn:121:in `<top (required)>'
21:47:05 web.1 | E, [2012-03-22T21:47:05.547966 #18938] ERROR -- : /Users/username/.rvm/gems/ruby-1.9.3-p125#project/bin/unicorn:19:in `load'
21:47:05 web.1 | E, [2012-03-22T21:47:05.548063 #18938] ERROR -- : /Users/username/.rvm/gems/ruby-1.9.3-p125#project/bin/unicorn:19:in `<main>'
Any ideas as to what may be going on here? I'm really not finding a solution right now that specifically addresses what to do in this scenario as far as poking and hunting down what really may be going on.
I know it's an old question, but I have the exact same issue. Requests from UptimeRobot and New Relic (and only from IPs from those two) give these log messages.
Both UptimeRobot and NewRelic reports 'OK'.
It seems that it is not the request that Rack::Lint is complaining about, but the response. Look at the stacktrace. It comes through http_response_write of unicorn (I too use unicorn).
I will investigate more and add any findings here.
UPDATE:
I am able to reproduce the issue with
$ curl https://example.com -X HEAD -i
HTTP/1.1 200 OK
Server: nginx/1.6.2 (Ubuntu)
Date: Wed, 18 Nov 2015 09:17:11 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 18422
Connection: keep-alive
Status: 200 OK
...
curl: (18) transfer closed with 18422 bytes remaining to read
So it seems that my old Rails is not supporting HEAD requests properly.
UPDATE: I am not able to reproduce on my vagrant box or on the staging server. Only difference from production I can think of is SSL.
Looks like your Uptime robot is sending a header with the wrong value. It should be sending the Content-length header with a value of 0 (or not sending it at all) but it's sending it with 31842, which is probably wrong.
You could direct it to some other http server, dump all headers and see why it is sending this or just change your uptime robot to not send this header.

Resources