Rails/Actionpack: warning: already initialized constant ICS - ruby

trying to start Rails server and getting a "warning" I don't understand. Anyone know what it means? warning: already initialized constant ICS
Here it is in context:
meltemi$ rails s
=> Booting WEBrick
=> Rails 3.1.3 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
/Users/meltemi/.rvm/gems/ruby-1.9.3-p0#summit/gems/actionpack-3.1.3/lib/action_dispatch/http/mime_type.rb:101: warning: already initialized constant ICS
[2012-01-15 12:28:34] INFO WEBrick 1.3.1
[2012-01-15 12:28:34] INFO ruby 1.9.3 (2011-10-30) [x86_64-darwin11.2.0]
[2012-01-15 12:28:34] INFO WEBrick::HTTPServer#start: pid=61345 port=3000

It looks like the "ICS" mime type is getting declared twice. If you can find once instance where it's being declared, maybe in config/initializers/mime_types.rb you can tack on an unless clause to it like this:
Mime::Type.register "text/calendar", :ics unless Mime::Type.lookup_by_extension(:ics)
This should only register the mime type if it doesn't already exist.

Related

NameError: uninitialized constant Mail::TestMailer on Elastic Beanstalk

I'm getting this error
NameError: uninitialized constant Mail::TestMailer
on my Ruby on Rails project on Elastic Beanstalk.
Other sources told me to install 3 gems.
gem 'net-smtp', '>= 0.3.3'
gem 'net-imap', '>= 0.1.2'
gem 'net-pop', '>= 0.1.2'
I have already installed them, but it still does not work.
eb deploy fails every time.
Ruby version 3.0.5, rails 6.1.7
Code from application mailer, not sure if this helps but just in case.
class ApplicationMailer < ActionMailer::Base
default from: 'from#example.com'
layout 'mailer'
end
Please see the error log below
eb deploy Creating application version archive "app-4523-230109_233425301397". Uploading: [##################################################] 100% Done... 2023-01-09 14:38:30 INFO Environment update is starting. 2023-01-09 14:38:36 INFO Deploying new version to instance(s). 2023-01-09 14:40:51 ERROR Instance deployment failed. For details, see 'eb-engine.log'. 2023-01-09 14:40:53 ERROR [Instance: i-0e263523f982bac43] Command failed on instance. Return code: 1 Output: Engine execution has encountered an error.. 2023-01-09 14:40:53 INFO Command execution completed on all instances. Summary: [Successful: 0, Failed: 1]. 2023-01-09 14:40:53 ERROR Unsuccessful command execution on instance id(s) 'i-0e263523f982bac43'. Aborting the operation. 2023-01-09 14:40:54 ERROR Failed to deploy application.
I hope this helps.
Let me know if you need more information.

What is the correct way to end a WEBrick server process after a timeout?

I'm trying to implement a small WEBrick server that ends itself when there are no requests after x number of seconds. However, I'm getting nowhere. My very first attempt at simply exiting after 2 seconds fails. Here's the simple code
that doesn't work.
server = WEBrick::HTTPServer.new(:Port => 8000)
WEBrick::Utils::TimeoutHandler.register(2, Timeout::Error)
server.start
I thought that would simply exit the process after 2 seconds. Here's what actually happens:
[2020-01-19 15:41:10] INFO WEBrick 1.4.2
[2020-01-19 15:41:10] INFO ruby 2.5.1 (2018-03-29) [x86_64-linux-gnu]
[2020-01-19 15:41:10] INFO WEBrick::HTTPServer#start: pid=16622 port=8000
[2020-01-19 15:41:12] ERROR Timeout::Error: execution timeout
/usr/lib/ruby/2.5.0/webrick/server.rb:170:in `select'
And then the process keeps running. I have to ctrl-c to end it.
What's the correct way to shut down a server and end the process after a timeout?

trying to run a testsuite for c with on a ruby server and it gives an error

* Starting server on port 18000
Visit http://localhost:18000 to view testsuite. *
*******************************************************
[2016-06-01 16:44:22] INFO WEBrick 1.3.1
[2016-06-01 16:44:22] INFO ruby 1.9.3 (2013-11-22) [x86_64-linux]
[2016-06-01 16:44:22] WARN TCPServer Error: Address already in use - bind(2)
[2016-06-01 16:44:22] INFO WEBrick::HTTPServer#start: pid=2736 port=18000
//after searching through the stackoverflow tried lsof -wni tcp:3000 and kill //-9 2376, didnt help
Tried it once more did work, dont know what the issue though

ssh proxy script runs in ruby but not in jruby

I have a ruby script that uses the net::ssh gem.
Its a simple script to tunnel through a jump-off server to a destination box. The box is only visible to the jump-off server. Here is the script:
require 'net/ssh/proxy/command'
require "net/ssh"
class TestTunnel
def initialize
proxy = Net::SSH::Proxy::Command.new('ssh admin#10.10.10.10 nc %h %p 2>/dev/null')
p "proxy gotten"
Net::SSH.start("host1", "admin", :password => "admin", :proxy => proxy) do |ssh|
hostname = ssh.exec!("hostname")
p "In #{hostname}"
end
end
end
b=TestTunnel.new
The issue is the script runs in ruby but not in jruby. My framework runs off jruby so I need to use it with jruby.
My solution was to call a bash script from my jruby script to setup the tunnel and run commands there but I would rather have everything done within jruby.
Here are the errors I get:
~/src/main/ruby$ jruby --1.9 scripts/test_tunnel.rb
"proxy gotten"
IO::EAGAINWaitReadable: Resource temporarily unavailable - errno backtraces disabled; run with -Xerrno.backtrace=true to enable
And when I run in ruby:
~/src/main/ruby$ ruby scripts/test_tunnel.rb
"proxy gotten"
"In vz-int-api02\n"
~/src/main/ruby$
When I run with -Xerrno.backtrace=true I can see that jruby is 1.7.9 and I can see that its using ruby 1.9:
~/src/main/ruby$ jruby -Xerrno.backtrace=true --1.9 scripts/test_tunnel.rb
"proxy gotten"
IO::EAGAINWaitReadable: Resource temporarily unavailable -
read_nonblock at org/jruby/RubyIO.java:2856
recv at /usr/local/jruby-1.7.9/lib/ruby/gems/shared/gems/net-ssh-2.9.2/lib/net/ssh/proxy/command.rb:75
fill at /usr/local/jruby-1.7.9/lib/ruby/gems/shared/gems/net-ssh-2.9.2/lib/net/ssh/buffered_io.rb:65
next_packet at /usr/local/jruby-1.7.9/lib/ruby/gems/shared/gems/net-ssh-2.9.2/lib/net/ssh/transport/packet_stream.rb:88
poll_message at /usr/local/jruby-1.7.9/lib/ruby/gems/shared/gems/net-ssh-2.9.2/lib/net/ssh/transport/session.rb:183
loop at org/jruby/RubyKernel.java:1519
poll_message at /usr/local/jruby-1.7.9/lib/ruby/gems/shared/gems/net-ssh-2.9.2/lib/net/ssh/transport/session.rb:178
wait at /usr/local/jruby-1.7.9/lib/ruby/gems/shared/gems/net-ssh-2.9.2/lib/net/ssh/transport/session.rb:215
loop at org/jruby/RubyKernel.java:1519
wait at /usr/local/jruby-1.7.9/lib/ruby/gems/shared/gems/net-ssh-2.9.2/lib/net/ssh/transport/session.rb:213
initialize at /usr/local/jruby-1.7.9/lib/ruby/gems/shared/gems/net-ssh-2.9.2/lib/net/ssh/transport/session.rb:87
start at /usr/local/jruby-1.7.9/lib/ruby/gems/shared/gems/net-ssh-2.9.2/lib/net/ssh.rb:207
initialize at scripts/test_tunnel.rb:8
(root) at scripts/test_tunnel.rb:15
~/src/main/ruby$ jruby -Xerrno.backtrace=true --1.9 --version
jruby 1.7.9 (1.9.3p392) 2013-12-06 87b108a on Java HotSpot(TM) 64-Bit Server VM 1.8.0_72-b15 +indy [linux-amd64]
~/src/main/ruby$
Is there any way to get this to run in jruby like it does in ruby or is my solution to call a bash script from within jruby the only way to do this?
A
This sounds a lot like this bug in net-ssh that was fixed in net-ssh 3.0.2.
The commit message that closed that issue t was "Bugfix: proxy command was using nonblocking io api incorrectly causing rare IO::EAGAIN errors" which sounds like exactly what you are getting.

Ruby crashes on windows

I'm facing same problem described here: why-rails-fails-with-ruby-exe-has-encountered-a-problem-and-needs-to-close. that is ruby get crashed with following error:
ruby.exe has encountered a problem and needs to close. We are sorry for the inconvenience.
I'm asking this to add some details on it as that question was not asked by me I am not able to add information in it. So this is not duplicate.
Ruby crashes eventually no matter how I run it (in development or in production), but it seems to crash more often in production mode. Sometimes it will crash when I hold down the F5 key, but sometimes I have to hold and release it intermittently for a minute or two. It appears to be very dependent on timing, but I can usually make it crash in less than 60 seconds.
When I refresh the GET request is sent for 3 times as follows:
Started GET "/app/page" for 127.0.0.1 at 2011-02-23 10:57:35 +0530
Processing by AppController#page as HTML
Rendered pms/dashboard.html.erb within layouts/application (109.4ms)
Completed 200 OK in 141ms (Views: 140.6ms | ActiveRecord: 0.0ms)
Started GET "/app/page" for 127.0.0.1 at 2011-02-23 10:57:35 +0530
Processing by AppController#page as */*
Rendered pms/dashboard.html.erb within layouts/application (15.6ms)
Completed 200 OK in 187ms (Views: 187.5ms | ActiveRecord: 0.0ms)
Started GET "/app/page" for 127.0.0.1 at 2011-02-23 10:57:35 +0530
Processing by AppController#page as */*
Rendered pms/dashboard.html.erb within layouts/application (15.6ms)
Completed 200 OK in 219ms (Views: 218.7ms | ActiveRecord: 0.0ms)
And if I rapidly refresh the page get following error in one of or all the 3 request:
ERROR Errno:ECONNABORTED: An established connection was aborted by the software in your host machine:
c:/Ruby/lib/1.9.1/webrick/httpresponse.rb:323:in 'write'
c:/Ruby/lib/1.9.1/webrick/httprespose.rb:323:in '<<'
c:/Ruby/lib/1.9.1/webrick/httprespose.rb:323:in '_write_data'
c:/Ruby/lib/1.9.1/webrick/httprespose.rb:295:in 'send_body_string'
c:/Ruby/lib/1.9.1/webrick/httprespose.rb:186:in 'send_body'
c:/Ruby/lib/1.9.1/webrick/httprespose.rb:103:in 'send_response'
c:/Ruby/lib/1.9.1/webrick/httpserver.rb:86:in 'run'
ERROR Errno:ECONNABORTED: An established connection was aborted by the software in your host machine:
c:/Ruby/lib/1.9.1/webrick/httpserver.rb:56:in 'eof?'
c:/Ruby/lib/1.9.1/webrick/httpserver.rb:56:in 'run'
c:/Ruby/lib/1.9.1/webrick/server.rb:183:in 'block in start_thread'
INFO going to shutdown....
INFO WEBrick::HTTPServer#start done
When I started to get this error?
When I added images, css and javascript in my project I started to get this error. I also tried by removing one of this 3 and see who causes the error but every time my ruby.exe get crashed and i see the error:
ruby.exe has encountered a problem and needs to close. We are sorry for the inconvenience.
How can I solve this?
When I start server following is printed on console:
=>Booting WEBrick
=>Rails 3.0.3 application starting in development on http://0.0.0.0:3000
=>Call with -d to detach
=>Ctrl-C to shutdown server
[2011-02-23 10:59:22] INFO WEBrick 1.3.1
[2011-02-23 10:59:22] INFO ruby 1.9.2 (2010-08-18) [i386-mingw32]
[2011-02-23 10:59:22] INFO WEbrick::HTTPServer#start: pid:2448 port=3000
Output of ruby -v
ruby 1.9.2p0 (2010-08-18) [i386-mingw32]
... except the installer is now ALSO the crashing 1.9.2-p290
Workaround:
Add (or change)
config.log_level = :warn
in config/environments/development.rb
(not my solution - found it in another thread)
Running 1.9.2 on windows puts you in a REALLY small minority of users. If you don't have an explicit need for 1.9, I'd use 1.8.7. Specifically, I'd use the package from RailsInstaller: http://railsinstaller.org/
i got the same crashes on windows 7 with 1.9.2-p290. someone said to clear development.log file. i can't believe but after deleting my 12mb development.log everything works fine.
it is possible that a native (C) extension is failing and bringing the whole ruby down; in my case it was sql server adapter looping indefinitely/using whole heap; after we traced and fixed the bug in the adapter (https://github.com/rails-sqlserver/tiny_tds/pull/124) it does not fail again

Resources