Ruby 2.7.4 Net Constant Warnings
Asked Answered
C

2

5

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?

Charlottetown answered 22/12, 2021 at 3:10 Comment(0)
H
8

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
Haslet answered 26/1, 2023 at 13:14 Comment(0)
C
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
Charlottetown answered 26/1, 2022 at 19:18 Comment(6)
I've removed my previous answer. It seems like updating to a newer version of bundler that supports the default gems is the right solutionTother
This did not work for me. The deleted answer from @Tother however did. Simply adding gem "net-http" to my Gemfile fixed this issue. My bundler was already updated as well.Ryannryazan
@Ryannryazan What version of Ruby? There were some versions recently that were heavy on these warnings.Charlottetown
@Charlottetown ruby -v gives me ruby 2.7.2p137Ryannryazan
Also for reference the net-http gem installed is version 0.2.2Ryannryazan
That version might be the noisy culprit. People started to complain this was happening for deprecated methods, etc.Charlottetown

© 2022 - 2024 — McMap. All rights reserved.