3

I'm getting repetitive warnings upon running a ruby script in a crontab, as well as manually in the terminal.

/Users/rich/.rbenv/versions/2.7.4/lib/ruby/2.7.0/net/protocol.rb:66: warning: already initialized constant Net::ProtocRetryError
/Users/rich/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/net-protocol-0.1.2/lib/net/protocol.rb:68: warning: previous definition of ProtocRetryError was here
/Users/rich/.rbenv/versions/2.7.4/lib/ruby/2.7.0/net/protocol.rb:206: warning: already initialized constant Net::BufferedIO::BUFSIZE
/Users/rich/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/net-protocol-0.1.2/lib/net/protocol.rb:208: warning: previous definition of BUFSIZE was here
/Users/rich/.rbenv/versions/2.7.4/lib/ruby/2.7.0/net/protocol.rb:503: warning: already initialized constant Net::NetPrivate::Socket
/Users/rich/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/net-protocol-0.1.2/lib/net/protocol.rb:504: warning: previous definition of Socket was here

I've changed the script to either use net/http or Faraday, the latter I'm assuming requires the first. Having seen this behaviour before recently and way back, this is a reload of the net gem, which is part of the core if I am correct. I'm just not sure why it's reloading.

I'm using rbenv to juggle ruby versions for a couple of reasons, and that won't change. My shebang is #!/Users/rich/.rbenv/shims/ruby but my ruby version is a bit different:

$ which ruby
==> /Users/rich/.rbenv/versions/2.7.4/bin/ruby

$ ruby -v
==> Ruby version: ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) [arm64-darwin21]

This slight difference from the shebang and requested versions of ruby might be the issue. I have many scripts that rely on that shebang, which points to the current rbenv version, which is what I want. I change versions from time to time and don't want to hard code that instruction.

Is there a way I can see why this is happening? How can I make these go away? How can I stop reloading core gems that are already loaded?

Rich_F
  • 1,830
  • 3
  • 24
  • 45

2 Answers2

6

I had to add the following 2 lines to the Gemfile to finally eliminate the all the warnings:

gem 'net-http'
gem 'uri', '0.10.0'    # force the default version for ruby 2.7
Juan Schwindt
  • 464
  • 4
  • 7
0

Bundler was the culprit with some dependency issues and reloading various versions on top of previous Gemfile.lock versions...something like that. Update this way:

bundle update --bundler
Rich_F
  • 1,830
  • 3
  • 24
  • 45
  • I've removed my previous answer. It seems like updating to a newer version of bundler that supports the default gems is the right solution – amcvitty Jan 27 '22 at 17:23
  • 2
    This did not work for me. The deleted answer from @amcvitty however did. Simply adding `gem "net-http"` to my `Gemfile` fixed this issue. My `bundler` was already updated as well. – aarona Oct 11 '22 at 16:22
  • @aarona What `version` of `Ruby`? There were some versions recently that were heavy on these warnings. – Rich_F Oct 11 '22 at 16:27
  • @Rich_F `ruby -v` gives me `ruby 2.7.2p137` – aarona Oct 11 '22 at 16:49
  • Also for reference the `net-http` gem installed is version `0.2.2` – aarona Oct 11 '22 at 16:50
  • That version might be the noisy culprit. People started to complain this was happening for deprecated methods, etc. – Rich_F Oct 11 '22 at 22:12