Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix missing ipaddr require #37

Merged
merged 2 commits into from
Apr 18, 2018

Conversation

colinsurprenant
Copy link
Contributor

The IPAddr class is used but the ipaddr library is never required. If no other plugins does a require "ipaddr" then the udp input will crash on startup with:

[WARN ][logstash.inputs.udp ] UDP listener died {:exception=>#<NameError: uninitialized constant LogStash::Inputs::Udp::IPAddr>, :backtrace=>["org/jruby/RubyModule.java:2746:in const_missing'", "/usr/share/logstash/vendor/bundle/jruby/1.9/gems/logstash-input-udp-3.3.1/lib/logstash/inputs/udp.rb:87:inudp_listener'", "/usr/share/logstash/vendor/bundle/jruby/1.9/gems/logstash-input-udp-3.3.1/lib/logstash/inputs/udp.rb:57:in run'", "/usr/share/logstash/logstash-core/lib/logstash/pipeline.rb:470:ininputworker'", "/usr/share/logstash/logstash-core/lib/logstash/pipeline.rb:463:in `start_input'"]}

This fix is simply to require that library.

@@ -4,6 +4,7 @@
require "logstash/namespace"
require "socket"
require "stud/interval"
require "ipaddr"
Copy link
Member

@jsvd jsvd Apr 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

meh - if you insist I canl do it but OTOH it's totally ok to require a lib that is used in the file. For example, if udp.rb stops using it but it's still in use in client.rb then it won't break. In fact I'd argue that this is preferable actually.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually ... doing that risks reproducing the exact same problem we are solving here :P

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess my argument comes from ipaddr now being a runtime dependency in the gemspec so it must be required in the "lib/" files not the "spec"

That said I'm not blocking this PR b/c of this, up to you.
LGTM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

« ipaddr now being a runtime dependency in the gemspec so it must be required in the "lib/" files not the "spec"» not following what you mean!?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ipaddr now being a runtime dependency in the gemspec

I forgot ipaddr is stdlib, but my argument was that any runtime dependency should be included in the lib/logstash/inputs/udp.rb, which means we'd never need to include in the specs.

I'm still LGTM on this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally think that not having an explicit require "somelib" in a file that explicitly uses Someclass is an anti-pattern. In this case the IPAddr class in client.rb is used independently for its usage in udp.rb and if one day IPAddr is not used anymore in udp.rb for whatever reason, that does not mean that IPAddr will not be used in client.rb and following your suggestion of removing require "ipaddr" from client.rb it would result in a bug when running specs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, agreed.

@@ -4,6 +4,7 @@
require "logstash/namespace"
require "socket"
require "stud/interval"
require "ipaddr"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess my argument comes from ipaddr now being a runtime dependency in the gemspec so it must be required in the "lib/" files not the "spec"

That said I'm not blocking this PR b/c of this, up to you.
LGTM

@colinsurprenant colinsurprenant merged commit cf26a05 into logstash-plugins:master Apr 18, 2018
@colinsurprenant
Copy link
Contributor Author

merged and published as v3.3.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants