xmpp4r throws exception on login: "Exception caught in Parser thread! (Jabber::ServerDisconnected)" - ruby

I tried to connect to my XMPP server using xmpp4r in ruby and my code is very simple, but I don't know why I got error.
I can successfully use ichat to log in using chat#localhost and also to the 5280/admin website.
require 'xmpp4r/client'
include Jabber
Jabber::debug = true
jid = Jabber::JID.new('chat#localhost')
client = Jabber::Client.new(jid)
client.connect
client.auth('123456')
client.close
And the error is:
D, [2013-02-18T03:24:55.768029 #15238] DEBUG -- : Debugging mode enabled.
W, [2013-02-18T03:24:55.768341 #15238] WARN -- : Warnings mode enabled.
D, [2013-02-18T03:24:55.772467 #15238] DEBUG -- : RESOLVING:
_xmpp-client._tcp.localhost (SRV)
D, [2013-02-18T03:24:55.778631 #15238] DEBUG -- : CONNECTING:
localhost:5222
D, [2013-02-18T03:24:55.780122 #15238] DEBUG -- : SENDING:
<stream:stream xmlns:stream='http://etherx.jabber.org/streams'
xmlns='jabber:client' to='localhost' xml:lang='en' version='1.0' >
D, [2013-02-18T03:24:55.782276 #15238] DEBUG -- : RECEIVED:
<stream:stream from='localhost' id='3021975152' xml:lang='en'
xmlns:stream='http://etherx.jabber.org/streams' version='1.0'
xmlns='jabber:client'/>
D, [2013-02-18T03:24:55.784022 #15238] DEBUG -- : RECEIVED:
<stream:features><mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
<mechanism>SCRAM-SHA-1</mechanism><mechanism>DIGEST-MD5</mechanism>
<mechanism>PLAIN</mechanism></mechanisms><c hash='sha-1'
node='http://www.process-one.net/en/ejabberd/'
ver='yy7di5kE0syuCXOQTXNBTclpNTo=' xmlns='http://jabber.org/protocol/caps'/>
<register xmlns='http://jabber.org/features/iq-register'/></stream:features>
D, [2013-02-18T03:24:55.784203 #15238] DEBUG -- : FEATURES: waiting...
D, [2013-02-18T03:24:55.784785 #15238] DEBUG -- : FEATURES: received
D, [2013-02-18T03:24:55.785290 #15238] DEBUG -- : PROCESSING:
<stream:features xmlns='jabber:client'><mechanisms
xmlns='urn:ietf:params:xml:ns:xmpp-sasl'><mechanism>SCRAM-SHA-1</mechanism>
<mechanism>DIGEST-MD5</mechanism><mechanism>PLAIN</mechanism></mechanisms><c
hash='sha-1' node='http://www.process-one.net/en/ejabberd/'
ver='yy7di5kE0syuCXOQTXNBTclpNTo=' xmlns='http://jabber.org/protocol/caps'/>
<register xmlns='http://jabber.org/features/iq-register'/></stream:features>
(REXML::Element)
D, [2013-02-18T03:24:55.785360 #15238] DEBUG -- : FEATURES: waiting finished
D, [2013-02-18T03:24:55.785450 #15238] DEBUG -- : TRYING stanzacbs...
D, [2013-02-18T03:24:55.785556 #15238] DEBUG -- : TRYING
message/iq/presence/cbs...
D, [2013-02-18T03:24:55.785987 #15238] DEBUG -- : SENDING:
<auth mechanism='DIGEST-MD5' xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/>
D, [2013-02-18T03:24:55.787784 #15238] DEBUG -- : RECEIVED:
<challenge xmlns='urn:ietf:params:xml:ns:xmppsasl'>bm9uY2U9IjE5NzEzNzk5NzQiLHFvcD0iYXV0aCIsY2hhcnNldD11dGYtOCxhbGdvcml0aG09bWQ1LXNlc3M=</challenge>
D, [2013-02-18T03:24:55.788143 #15238] DEBUG -- : SASL DIGEST-MD5 challenge:
nonce="1971379974",qop="auth",charset=utf-8,algorithm=md5-sess
{"nonce"=>"1971379974", "qop"=>"auth", "charset"=>"utf-8", "algorithm"=>"md5-sess"}
D, [2013-02-18T03:24:55.788475 #15238] DEBUG -- : SASL DIGEST-MD5 response:
nonce="1971379974",charset=utf-8,username="chat",realm="localhost",cnonce="92a37c018b9c32339c4b52ee0b02d67e",nc=00000001,qop=auth,digest-uri="xmpp/localhost",response=9c6bca9f4cf6f8daf3197a914023729a
{"nonce"=>"\"1971379974\"", "charset"=>"utf-8", "username"=>"\"chat\"", "realm"=>"\"localhost\"", "cnonce"=>"\"92a37c018b9c32339c4b52ee0b02d67e\"", "nc"=>"00000001", "qop"=>"auth", "digest-uri"=>"\"xmpp/localhost\"", "response"=>"9c6bca9f4cf6f8daf3197a914023729a"}
D, [2013-02-18T03:24:55.788761 #15238] DEBUG -- : SENDING:
<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>bm9uY2U9IjE5NzEzNzk5NzQiLGNoYXJzZXQ9dXRmLTgsdXNlcm5hbWU9ImNoYXQiLHJlYWxtPSJsb2NhbGhvc3QiLGNub25jZT0iOTJhMzdjMDE4YjljMzIzMzljNGI1MmVlMGIwMmQ2N2UiLG5jPTAwMDAwMD
AxLHFvcD1hdXRoLGRpZ2VzdC11cmk9InhtcHAvbG9jYWxob3N0IixyZXNwb25zZT05YzZiY2E5ZjRjZjZm
OGRhZjMxOTdhOTE0MDIzNzI5YQ==</response>
D, [2013-02-18T03:24:55.818548 #15238] DEBUG -- : RECEIVED:
<challenge xmlns='urn:ietf:params:xml:ns:xmpp-
sasl'>cnNwYXV0aD01NTQ2NTVlYjljYWUzZGExMjhmZjBkMWUzNDUzYmIwZQ==</challenge>
D, [2013-02-18T03:24:55.819064 #15238] DEBUG -- : SENDING:
<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/>
D, [2013-02-18T03:24:56.147820 #15238] DEBUG -- : RECEIVED:
<success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/>
D, [2013-02-18T03:24:56.148432 #15238] DEBUG -- : SENDING:
<stream:stream xmlns:stream='http://etherx.jabber.org/streams'
xmlns='jabber:client' to='localhost' xml:lang='en' version='1.0' >
D, [2013-02-18T03:25:56.151018 #15238] DEBUG -- : SENDING:
W, [2013-02-18T03:25:56.212617 #15238] WARN -- : EXCEPTION:
Jabber::ServerDisconnected
Server Disconnected!
/home/ubuntu/.rvm/gems/ruby-1.9.3-p385/gems/xmpp4r-
0.5/lib/xmpp4r/streamparser.rb:68:in `block in parse'
/home/ubuntu/.rvm/rubies/ruby-1.9.3-
p385/lib/ruby/1.9.1/rexml/parsers/sax2parser.rb:195:in `call'
/home/ubuntu/.rvm/rubies/ruby-1.9.3-
p385/lib/ruby/1.9.1/rexml/parsers/sax2parser.rb:195:in `block in handle'
/home/ubuntu/.rvm/rubies/ruby-1.9.3-
p385/lib/ruby/1.9.1/rexml/parsers/sax2parser.rb:195:in `each'
/home/ubuntu/.rvm/rubies/ruby-1.9.3-
p385/lib/ruby/1.9.1/rexml/parsers/sax2parser.rb:195:in `handle'
/home/ubuntu/.rvm/rubies/ruby-1.9.3-
p385/lib/ruby/1.9.1/rexml/parsers/sax2parser.rb:95:in `parse'
/home/ubuntu/.rvm/gems/ruby-1.9.3-p385/gems/xmpp4r-
0.5/lib/xmpp4r/streamparser.rb:79:in `parse'
/home/ubuntu/.rvm/gems/ruby-1.9.3-p385/gems/xmpp4r-
0.5/lib/xmpp4r/stream.rb:75:in `block in start'
W, [2013-02-18T03:25:56.212740 #15238] WARN -- : Exception caught in Parser
thread! (Jabber::ServerDisconnected)
/home/ubuntu/.rvm/gems/ruby-1.9.3-p385/gems/xmpp4r-
0.5/lib/xmpp4r/streamparser.rb:68:in `block in parse'
Any ideas?
Thanks!!

I also faced this issue when sending message over facebook using Jabber.
Even wrapped in a try/catch, sometimes, Jabber::ServerDisconnected thrown and caused web server stop.
In xmpp4r source code, they thrown Jabber::ServerDisconnected when received disconnected signal and Thread.abort_on_exception = true in each thread
Ref https://github.com/lnussbaum/xmpp4r/blob/master/lib/xmpp4r/streamparser.rb and https://github.com/lnussbaum/xmpp4r/blob/master/lib/xmpp4r/stream.rb
I guess exception thrown in an orphan thread.
I have no solution, but a workaround that set Thread::abort_on_exception = false globally (in class/method using Jabber). So exception still thrown, but we ignore it.

There is a better way of handling errors, as mentioned in the docs:
If you want your connection to survive disconnects and timeouts, catch exception in Stream#on_exception and re-call Client#connect and Client#auth. Don‘t forget to re-send initial Presence and everything else you need to setup your session.
Stream#on_exception link

Related

Ruby/Heroku app errors "We're sorry, but something went wrong" troubleshooting

I am trying to setup an Elo rating system for my local 8 ball pool league using:
https://github.com/elovation/elovation
The only changes I have made to above repo prior to deployment are specifying heroku:stack-18 in app.json and running bundle install after specifying to use https:// instead of git://
I have deployed my app to Heroku without error but when loading my app I get a "We're sorry, something went wrong page"
After deployment I have ran heroku run rake db:migrate and heroku restart but my error persists
I have included below output of heroku logs ; any help with the below errors would be greatly appreciated as I am not particularly familiar with Ruby or Heroku postgres.
2022-06-21T12:54:08.886300+00:00 app[web.1]: I, [2022-06-21T12:54:08.886206 #9] INFO -- : [dc5be6b7-715a-47a0-8936-e0ba1c6b2c13] Processing by DashboardController#show as HTML
2022-06-21T12:54:08.888800+00:00 app[web.1]: D, [2022-06-21T12:54:08.888726 #9] DEBUG -- : [dc5be6b7-715a-47a0-8936-e0ba1c6b2c13] Player Load (0.5ms) SELECT "players".* FROM "players"
2022-06-21T12:54:08.889854+00:00 app[web.1]: I, [2022-06-21T12:54:08.889789 #9] INFO -- : [dc5be6b7-715a-47a0-8936-e0ba1c6b2c13] Rendering dashboard/show.html.erb within layouts/application
2022-06-21T12:54:08.891005+00:00 app[web.1]: D, [2022-06-21T12:54:08.890942 #9] DEBUG -- : [dc5be6b7-715a-47a0-8936-e0ba1c6b2c13] Game Load (0.5ms) SELECT "games".* FROM "games" ORDER BY updated_at DESC
2022-06-21T12:54:08.891468+00:00 app[web.1]: I, [2022-06-21T12:54:08.891374 #9] INFO -- : [dc5be6b7-715a-47a0-8936-e0ba1c6b2c13] Rendered dashboard/show.html.erb within layouts/application (1.5ms)
2022-06-21T12:54:08.893279+00:00 app[web.1]: I, [2022-06-21T12:54:08.893225 #9] INFO -- : [dc5be6b7-715a-47a0-8936-e0ba1c6b2c13] Completed 500 Internal Server Error in 7ms (ActiveRecord: 1.1ms)
2022-06-21T12:54:08.894220+00:00 app[web.1]: F, [2022-06-21T12:54:08.894169 #9] FATAL -- : [dc5be6b7-715a-47a0-8936-e0ba1c6b2c13]
2022-06-21T12:54:08.894271+00:00 app[web.1]: F, [2022-06-21T12:54:08.894239 #9] FATAL -- : [dc5be6b7-715a-47a0-8936-e0ba1c6b2c13] ActionView::Template::Error (The asset "chartkick.js" is not present in the asset pipeline.
2022-06-21T12:54:08.894272+00:00 app[web.1]: ):
2022-06-21T12:54:08.894439+00:00 app[web.1]: F, [2022-06-21T12:54:08.894403 #9] FATAL -- : [dc5be6b7-715a-47a0-8936-e0ba1c6b2c13] 11: <%= csrf_meta_tags %>
2022-06-21T12:54:08.894440+00:00 app[web.1]: [dc5be6b7-715a-47a0-8936-e0ba1c6b2c13] 12: <link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,700' rel='stylesheet' type='text/css'>
2022-06-21T12:54:08.894441+00:00 app[web.1]: [dc5be6b7-715a-47a0-8936-e0ba1c6b2c13] 13:
2022-06-21T12:54:08.894441+00:00 app[web.1]: [dc5be6b7-715a-47a0-8936-e0ba1c6b2c13] 14: <%= javascript_include_tag "//www.google.com/jsapi", "chartkick" %>
2022-06-21T12:54:08.894442+00:00 app[web.1]: [dc5be6b7-715a-47a0-8936-e0ba1c6b2c13] 15: </head>
2022-06-21T12:54:08.894442+00:00 app[web.1]: [dc5be6b7-715a-47a0-8936-e0ba1c6b2c13] 16: <body>
2022-06-21T12:54:08.894443+00:00 app[web.1]: [dc5be6b7-715a-47a0-8936-e0ba1c6b2c13] 17: <div id='container'>
2022-06-21T12:54:08.894482+00:00 app[web.1]: F, [2022-06-21T12:54:08.894452 #9] FATAL -- : [dc5be6b7-715a-47a0-8936-e0ba1c6b2c13]
2022-06-21T12:54:08.894523+00:00 app[web.1]: F, [2022-06-21T12:54:08.894495 #9] FATAL -- : [dc5be6b7-715a-47a0-8936-e0ba1c6b2c13] app/views/layouts/application.html.erb:14:in `_app_views_layouts_application_html_erb___4496802780226790006_47054455194320'

Redmine is down after attempt to setup smtp configuration

Today I set up a Redmine instance on Ubuntu Server 20.04 for the first time. That worked out quite well so far. So afterwards I set up a Mattermost instance and installed the Redmine Messenger plugin to receive status updates from Redmine in Mattermost. That also worked brilliantly.
Then I wanted to activate email notifications. That unfortunately did not work.
I did the following:
fabrice#redmine:/etc/redmine/default$ sudo nano configuration.yml
and added the following content (with my information)
# Outgoing email settings
production:
email_delivery:
delivery_method: :smtp
smtp_settings:
address: smtp.example.net
port: 25
domain: example.net
authentication: :login
user_name: redmine#example.net
password: redmine
Then I restarted apache and then redmine was down. See image
errormessage
So I deleted the configuration.yml file and restarted apache. Unfortunately that didn't help. I couldn't take any usable information from the logs. (Which doesn't mean there aren't any)
If anyone has an idea how to get Redmine working again, I would be very grateful.
Last lines of redmine production log:
[ActiveJob] Enqueued ActionMailer::DeliveryJob (Job ID: 93923d8a-4e24-4467-847c-b2bdd774fd07) to Async(mailers) with arguments: "Mailer", "settings_updated", "deliver_now", #<GlobalID:0x00007fe514b9c070 #uri=#<URI::GID gid://redmine-app/User/1>>, #<GlobalID:0x00007fe514b938a8 #uri=#<URI::GID gid://redmine-app/User/1>>, ["login_required", "password_min_length"], {:remote_ip=>"192.168.178.174"}
Redirected to http://192.168.178.88/redmine/settings?tab=authentication
Completed 302 Found in 101ms (ActiveRecord: 62.6ms)
[ActiveJob] [ActionMailer::DeliveryJob] [93923d8a-4e24-4467-847c-b2bdd774fd07] Performing ActionMailer::DeliveryJob (Job ID: 93923d8a-4e24-4467-847c-b2bdd774fd07) from Async(mailers) with arguments: "Mailer", "settings_updated", "deliver_now", #<GlobalID:0x00007fe514b674d8 #uri=#<URI::GID gid://redmine-app/User/1>>, #<GlobalID:0x00007fe514b66bf0 #uri=#<URI::GID gid://redmine-app/User/1>>, ["login_required", "password_min_length"], {:remote_ip=>"192.168.178.174"}
[ActiveJob] [ActionMailer::DeliveryJob] [93923d8a-4e24-4467-847c-b2bdd774fd07] Rendering mailer/settings_updated.text.erb within layouts/mailer
[ActiveJob] [ActionMailer::DeliveryJob] [93923d8a-4e24-4467-847c-b2bdd774fd07] Rendered mailer/settings_updated.text.erb within layouts/mailer (3.9ms)
[ActiveJob] [ActionMailer::DeliveryJob] [93923d8a-4e24-4467-847c-b2bdd774fd07] Rendering mailer/settings_updated.html.erb within layouts/mailer
[ActiveJob] [ActionMailer::DeliveryJob] [93923d8a-4e24-4467-847c-b2bdd774fd07] Rendered mailer/settings_updated.html.erb within layouts/mailer (1.1ms)
[ActiveJob] [ActionMailer::DeliveryJob] [93923d8a-4e24-4467-847c-b2bdd774fd07] Performed ActionMailer::DeliveryJob (Job ID: 93923d8a-4e24-4467-847c-b2bdd774fd07) from Async(mailers) in 28.37ms
Started GET "/redmine/settings?tab=authentication" for 192.168.178.174 at 2021-04-13 11:44:09 +0000
Processing by SettingsController#index as HTML
Parameters: {"tab"=>"authentication"}
Settings cache cleared.
Current user: admin (id=1)
Rendering settings/edit.html.erb within layouts/admin
Rendered settings/_general.html.erb (12.0ms)
Rendered settings/_display.html.erb (15.5ms)
Rendered settings/_authentication.html.erb (13.0ms)
Rendered settings/_api.html.erb (4.0ms)
Rendered settings/_projects.html.erb (9.1ms)
Rendered settings/_users.html.erb (12.4ms)
Rendered queries/_columns.html.erb (6.2ms)
Rendered settings/_issues.html.erb (22.5ms)
Rendered queries/_columns.html.erb (3.3ms)
Rendered settings/_timelog.html.erb (8.1ms)
Rendered settings/_attachments.html.erb (5.7ms)
Rendered settings/_notifications.html.erb (0.4ms)
Rendered settings/_mail_handler.html.erb (8.4ms)
Rendered settings/_repositories.html.erb (12.9ms)
Rendered common/_tabs.html.erb (129.0ms)
Rendered settings/edit.html.erb within layouts/admin (129.3ms)
Rendered admin/_menu.html.erb (2.2ms)
Rendering layouts/base.html.erb
Rendered layouts/base.html.erb (7.4ms)
Completed 200 OK in 147ms (Views: 109.9ms | ActiveRecord: 32.0ms)
Edit:
sudo cat error.log | grep redmine
[ 2021-04-15 08:41:59.5086 21857/7f6e840bb700 age/Cor/App/Implementation.cpp:304 ]: Could not spawn process for application /usr/share/redmine: An error occurred while starting up the preloader.
/usr/share/redmine/config/application.rb:3:in `require'
/usr/share/redmine/config/application.rb:3:in `<top (required)>'
/usr/share/redmine/config/environment.rb:2:in `require'
/usr/share/redmine/config/environment.rb:2:in `<top (required)>'
[ 2021-04-15 09:31:14.7130 34932/7f564044f700 age/Cor/App/Implementation.cpp:304 ]: Could not spawn process for application /usr/share/redmine: An error occurred while starting up the preloader.
/usr/share/redmine/config/application.rb:3:in `require'
/usr/share/redmine/config/application.rb:3:in `<top (required)>'
/usr/share/redmine/config/environment.rb:2:in `require'
/usr/share/redmine/config/environment.rb:2:in `<top (required)>'
[ 2021-04-15 09:36:11.5553 38233/7f07082a9700 age/Cor/App/Implementation.cpp:304 ]: Could not spawn process for application /usr/share/redmine: An error occurred while starting up the preloader.
/usr/share/redmine/config/application.rb:3:in `require'
/usr/share/redmine/config/application.rb:3:in `<top (required)>'
/usr/share/redmine/config/environment.rb:2:in `require'
/usr/share/redmine/config/environment.rb:2:in `<top (required)>'
[ 2021-04-15 09:44:59.2308 38883/7f837c1b4700 age/Cor/App/Implementation.cpp:304 ]: Could not spawn process for application /usr/share/redmine: An error occurred while starting up the preloader.
/usr/share/redmine/config/application.rb:3:in `require'
/usr/share/redmine/config/application.rb:3:in `<top (required)>'
/usr/share/redmine/config/environment.rb:2:in `require'
/usr/share/redmine/config/environment.rb:2:in `<top (required)>'

Rails Admin POST requests cause H15 error on Heroku

I have a rails app that is working fine on Heroku, but all the POST requests coming from Rails admin are hanging for 55 seconds before causing a H15 "Idle Connection" error.
I've read that it can come from:
ActionCable not pinging the server during 55 consecutive seconds but I'm not using real time features with Rails Admin and I removed my ActionCable code to test and the problem still occurs
The server tries to return a response to a different IP than the one that initiated the call once you've configured your DNS, but I'm not, I'm not using a custom domain name, I use the my website-herokuapp.com one.
Here's the log of a POST request from my app from the admin:
2021-01-24T19:09:36.245896+00:00 app[web.1]: I, [2021-01-24T19:09:36.245747 #4] INFO -- : source=rack-timeout id=21d5a60a-a82a-4cf7-bbe1-b0254f5823c7 wait=11ms timeout=15000ms state=ready
2021-01-24T19:09:36.246186+00:00 app[web.1]: D, [2021-01-24T19:09:36.246074 #4] DEBUG -- : source=rack-timeout id=21d5a60a-a82a-4cf7-bbe1-b0254f5823c7 wait=11ms timeout=15000ms service=0ms state=active
2021-01-24T19:09:36.246456+00:00 app[web.1]: I, [2021-01-24T19:09:36.246394 #4] INFO -- : [21d5a60a-a82a-4cf7-bbe1-b0254f5823c7] Started PUT "/admin/first_job/252990/edit" for 92.183.112.168 at 2021-01-24 19:09:36 +0000
2021-01-24T19:09:36.248487+00:00 app[web.1]: I, [2021-01-24T19:09:36.248393 #4] INFO -- : [21d5a60a-a82a-4cf7-bbe1-b0254f5823c7] Processing by RailsAdmin::MainController#edit as HTML
2021-01-24T19:09:36.248636+00:00 app[web.1]: I, [2021-01-24T19:09:36.248524 #4] INFO -- : [21d5a60a-a82a-4cf7-bbe1-b0254f5823c7] Parameters: {"utf8"=>"✓", "authenticity_token"=>"9QGOhotnG3BkLq6TbkXuXZgMVxJ+AinueV0oEUaVw5iaQ6DRJukISaCV4x+lcpXog9ExNYf9DB8/u/jufN6+Dg==", "first_job"=>{"company_name"=>"My company"}, "return_to"=>"https://mywebsite-staging.herokuapp.com/admin/first_job", "_save"=>"", "model_name"=>"first_job", "id"=>"252990"}
2021-01-24T19:09:36.285663+00:00 app[web.1]: D, [2021-01-24T19:09:36.285530 #4] DEBUG -- : [21d5a60a-a82a-4cf7-bbe1-b0254f5823c7] User Load (1.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 307509], ["LIMIT", 1]]
2021-01-24T19:09:36.307192+00:00 app[web.1]: D, [2021-01-24T19:09:36.307039 #4] DEBUG -- : [21d5a60a-a82a-4cf7-bbe1-b0254f5823c7] FirstJob Load (2.0ms) SELECT "first_jobs".* FROM "first_jobs" WHERE "first_jobs"."id" = $1 ORDER BY "first_jobs"."id" ASC LIMIT $2 [["id", 252990], ["LIMIT", 1]]
2021-01-24T19:09:36.312261+00:00 app[web.1]: D, [2021-01-24T19:09:36.312087 #4] DEBUG -- : [21d5a60a-a82a-4cf7-bbe1-b0254f5823c7] (1.0ms) BEGIN
2021-01-24T19:09:36.317945+00:00 app[web.1]: D, [2021-01-24T19:09:36.317805 #4] DEBUG -- : [21d5a60a-a82a-4cf7-bbe1-b0254f5823c7] Company Load (1.8ms) SELECT "companies".* FROM "companies" WHERE "companies"."id" = $1 LIMIT $2 [["id", 26218], ["LIMIT", 1]]
2021-01-24T19:09:36.322239+00:00 app[web.1]: D, [2021-01-24T19:09:36.322101 #4] DEBUG -- : [21d5a60a-a82a-4cf7-bbe1-b0254f5823c7] (1.1ms) COMMIT
2021-01-24T19:09:36.323441+00:00 app[web.1]: I, [2021-01-24T19:09:36.323351 #4] INFO -- : [21d5a60a-a82a-4cf7-bbe1-b0254f5823c7] Redirected to https://mywebsite-staging.herokuapp.com/admin/first_job
2021-01-24T19:09:36.324756+00:00 app[web.1]: I, [2021-01-24T19:09:36.324674 #4] INFO -- : Completed 302 Found in 76ms (ActiveRecord: 19.6ms)
2021-01-24T19:09:36.324858+00:00 app[web.1]: I, [2021-01-24T19:09:36.324425 #4] INFO -- : source=rack-timeout id=21d5a60a-a82a-4cf7-bbe1-b0254f5823c7 wait=11ms timeout=15000ms service=79ms state=completed
2021-01-24T19:10:31.518929+00:00 heroku[router]: at=error code=H15 desc="Idle connection" method=POST path="/admin/first_job/252990/edit" host=mywebsite-staging.herokuapp.com request_id=21d5a60a-a82a-4cf7-bbe1-b0254f5823c7 fwd="92.183.112.168" dyno=web.1 connect=0ms service=55282ms status=503 bytes= protocol=https
Oh and of course, everything is working fine on my local.
Do someone has an idea?

mechanize and Ruby multipart/form-data - content transfer encoding

I am trying to dispatch a multipart/form-data POST request to a remote server using mechanize 2.7.3 to automate some interactions with a remote server. Unfortunally there is no usable <form>, so I have to issue the POST directly. Luckily, mechanize recognizes what I am up to anyway, but the server doesn't accept the response:
c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mechanize-2.7.3/lib/mechanize/http/agent.rb:308: in `fetch': 400 => Net::HTTPBadRequest for http://REDACTED/api/resources -- unhandled response (Mechanize::ResponseCodeError)
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mechanize-2.7.3/lib/mechanize.rb:1281:in `post_form'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mechanize-2.7.3/lib/mechanize.rb:502:in `post'
from thing.rb:38:in `upload'
Here's what mechanize logging output looks like during the request in question:
D, [2014-05-13T12:40:34.580906 #3456] DEBUG -- : query: "--cNPsKCeBSrPGUwxyjMze\r\nContent-Disposition: form-data; name=\"force_create\"\r\n\r\ntrue\r\n--cNPsKCeBSrPGUwxyjMze\r\nContent-Disposition: form-data; name=\"file\"; filename=\"test.wgt\"\r\nContent-Transfer-Encoding: binary\r\n\r\nREDACTED\r\n--cNPsKCeBSrPGUwxyjMze--\r\n"
I, [2014-05-13T12:40:34.581906 #3456] INFO -- : Net::HTTP::Post: /api/resources
D, [2014-05-13T12:40:34.581906 #3456] DEBUG -- : request-header: accept => */*
D, [2014-05-13T12:40:34.581906 #3456] DEBUG -- : request-header: user-agent => Mechanize/2.7.3 Ruby/1.9.3p392 (http://github.com/sparklemotion/mechanize/)
D, [2014-05-13T12:40:34.581906 #3456] DEBUG -- : request-header: accept-encoding => gzip,deflate,identity
D, [2014-05-13T12:40:34.581906 #3456] DEBUG -- : request-header: accept-charset => ISO-8859-1,utf-8;q=0.7,*;q=0.7
D, [2014-05-13T12:40:34.582906 #3456] DEBUG -- : request-header: accept-language => en-us,en;q=0.5
D, [2014-05-13T12:40:34.582906 #3456] DEBUG -- : request-header: cookie => csrftoken=G4dZv6fxRMq0Y2h5yntDsJTFBeEKVFaU; sessionid=9oqufupdt6r620eyep4l4jcl6i2cxda5
D, [2014-05-13T12:40:34.582906 #3456] DEBUG -- : request-header: host => REDACTED
D, [2014-05-13T12:40:34.582906 #3456] DEBUG -- : request-header: referer => REDACTED/login
D, [2014-05-13T12:40:34.582906 #3456] DEBUG -- : request-header: content-type => multipart/form-data; boundary=cNPsKCeBSrPGUwxyjMze
D, [2014-05-13T12:40:34.582906 #3456] DEBUG -- : request-header: content-length => 409
I, [2014-05-13T12:40:34.613906 #3456] INFO -- : status: Net::HTTPBadRequest 1.1 400 BAD REQUEST
D, [2014-05-13T12:40:34.613906 #3456] DEBUG -- : response-header: date => Tue, 13 May 2014 10:33:44 GMT
D, [2014-05-13T12:40:34.613906 #3456] DEBUG -- : response-header: server => Apache/2.2.15 (CentOS)
D, [2014-05-13T12:40:34.613906 #3456] DEBUG -- : response-header: vary => Accept-Language,Cookie,Accept-Encoding
D, [2014-05-13T12:40:34.613906 #3456] DEBUG -- : response-header: content-language => en
D, [2014-05-13T12:40:34.613906 #3456] DEBUG -- : response-header: content-type => text/plain; charset=utf-8
D, [2014-05-13T12:40:34.613906 #3456] DEBUG -- : response-header: content-encoding => gzip
D, [2014-05-13T12:40:34.613906 #3456] DEBUG -- : response-header: content-length => 37
D, [2014-05-13T12:40:34.613906 #3456] DEBUG -- : response-header: connection => close
D, [2014-05-13T12:40:34.614906 #3456] DEBUG -- : Read 37 bytes (37 total)
D, [2014-05-13T12:40:34.614906 #3456] DEBUG -- : gzip response
This is how I do it in Ruby:
def upload(file)
agent.post(base_uri + RESOURCES_PATH, {
:force_create => true,
:file => File.new(file)
}) do … end
end
Every other interaction with the site works normally (mechanize actually even logs in first, thus the cookies). The upload also works fine in a real browser – the only discernable difference is the content transfer encoding (octet-stream instead of binary). Or maybe I am missing something here? Something vital?
Also, I can't say much about the remote server in question. I only know the site is running some sort of Python-based framework (Django, iirc).
Thanks in advance,
Manuel
I have managed to identify the culprit here. As my development machine is Windows-based, this seems to have been an issue with mechanize (or one of its dependencies) and Windows. By specifying the b (binary) part in the second argument of File.new, the problem went away on its own. tl;dr: here's how the working code fragment now looks like:
agent.post(base_uri + RESOURCES_PATH, {
:force_create => true,
:file => File.new(file, 'rb') # <-- changed
})

Heroku Postgres Out of Memory error

My Rails app has been running fine until this morning. I tried restarting the app and here is the error i'm getting before i even hit a page. Out of Memory error on the Postgres connection! I can connect fine to the database from my dev machine. I have a Dev account with Heroku Postgres. I also ran that that SQL statement, and it was fine it should just return 1.
The config var DATABASE_URL is set correctly.
Any ideas?
thx,
matt
app[web.1]: => Booting WEBrick
app[web.1]: => Rails 3.2.13 application starting in production on http://0.0.0.0:23827
app[web.1]: => Call with -d to detach
app[web.1]: => Ctrl-C to shutdown server
app[web.1]: Exiting
app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:1161:in `exec': PG::OutOfMemory: ERROR: out of memory (ActiveRecord::StatementInvalid)
app[web.1]: DETAIL: Failed on request of size 96.
app[web.1]: : SELECT COUNT(*)
app[web.1]: FROM pg_class c
app[web.1]: LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
app[web.1]: WHERE c.relkind in ('v','r')
app[web.1]: AND c.relname = 'spree_shipments'
app[web.1]: AND n.nspname = ANY (current_schemas(false))
app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2

Resources