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

IOError: org.apache.log4j.spi.LoggingEvent; class invalid for deserialization #35

Closed
clevertension opened this issue Nov 7, 2016 · 19 comments

Comments

@clevertension
Copy link

  • Version: logstash-5.0.0
  • Operating System: CentOS Linux release 7.2.1511
  • Config File (if you have sensitive info, please remove it):
    input {
    log4j {
    mode => "server"
    host => "192.168.1.6"
    port => 4567
    type => "log4j"
    }
    }
    filter {
    }
    output {
    elasticsearch {
    action => "index" #The operation on ES
    hosts => "localhost:9200" #ElasticSearch host, can be array.
    index => "logstash-1" #The index to write data to.
    user => logstash_internal
    password => changeme
    }
    }
  • Sample Data:
  • Steps to Reproduce:
    when i use log4j in java to print something, the logstash error log is
org/jruby/ext/jruby/JRubyObjectInputStream.java:58:in `read_object'
/opt/logstash/logstash-5.0.0/vendor/bundle/jruby/1.9/gems/logstash-input-log4j-3.0.3-java/lib/logstash/inputs/log4j.rb:105:in `handle_socket'
/opt/logstash/logstash-5.0.0/vendor/bundle/jruby/1.9/gems/logstash-input-log4j-3.0.3-java/lib/logstash/inputs/log4j.rb:160:in `run'
[2016-11-07T16:10:45,022][DEBUG][logstash.inputs.log4j    ] Closing connection {:client=>"192.168.1.243:62896", :exception=>#<IOError: org.apache.log4j.spi.LoggingEvent; class invalid for deserialization>}
@jordansissel
Copy link
Contributor

jordansissel commented Nov 9, 2016

It sounds like logstash is connecting just fine (the subject of this issue says "can't connect to logstash").

As for your error output, I don't know what to make of it. It is looking for a class org.apache.log4j.spi.LoggingEvent but is thinking it can't deserialize them?

What version of log4j are you using to send?

Also, I am unfamiliar with log4j's serialization, so I'm only guessing here.

@clevertension
Copy link
Author

I am using log4j-1.2.17, when i downgrade the logstash to 2.4.0, everything is ok

@clevertension clevertension changed the title can't connect to logstash IOError: org.apache.log4j.spi.LoggingEvent; class invalid for deserialization Nov 9, 2016
@TandooriC
Copy link

I too is facing the same problem. I tried with the same parameters as @clevertension, log4j 1.2.17 and logstash 5.0.0. There is no error shown in the stdout and subsequent logs to the port gets exceptions. Downgrading to logstash 2.4 works.

@zvving
Copy link

zvving commented Nov 23, 2016

some problem +1

@jordansissel
Copy link
Contributor

jordansissel commented Nov 23, 2016

Based on @zvving commenting on this and #13, I am closing this as a duplicate of #13.

@zvving
Copy link

zvving commented Nov 23, 2016

@jordansissel OK, tks!

Now how to provisional fixed it, or must to downgrading to 2.4 ?

@jordansissel
Copy link
Contributor

As a workaround, I am seeing several reports in this ticket that downgrading to Logstash 2.4 works. If you need a solution now, please downgrade to Logstash 2.4.

@jordansissel
Copy link
Contributor

I think I have found the problem. There is a bug in log4j 2 where the "log4j 1.2" API provided by log4j2 has the LoggingEvent class that is not serializable, so Logstash rejects it. I have details in this ticket: #36 (comment)

Fixing this may require a new release of Logstash because I had to patch logstash itself to make this work.

@jordansissel
Copy link
Contributor

A workaround for Logstash 5.0.0 and 5.0.1:

There's a file logstash-core/lib/jars.rb with this line:

require_jar('org.apache.logging.log4j', 'log4j-1.2-api', '2.6.2')

If you comment it out, log4j input works successfully for me with Logstash 5.0.1.

Here's the patch:

--- old/logstash-core/lib/jars.rb	2016-11-28 16:07:07.208906014 -0800
+++ new/logstash-core/lib/jars.rb	2016-11-28 16:07:09.266844854 -0800
@@ -1,5 +1,5 @@
 require 'jar_dependencies'
-require_jar('org.apache.logging.log4j', 'log4j-1.2-api', '2.6.2')
+#require_jar('org.apache.logging.log4j', 'log4j-1.2-api', '2.6.2')
 require_jar('org.apache.logging.log4j', 'log4j-api', '2.6.2')
 require_jar('org.apache.logging.log4j', 'log4j-core', '2.6.2')
 require_jar('com.fasterxml.jackson.core', 'jackson-core', '2.7.4')

You can apply it with patch -p1 if you are familiar with the patch tool.

This patch is probably not supported and we should have this bug fixed for Logstash 5.1.0

@npomaroli
Copy link

One more thing about this issue: I got no log message on the logstash side for this problem until I raised the level to DEBUG.
I think that's wrong. When an input plugin refuses to work (and closes the connection), because it can't handle the data someone's sending it, it should clearly not do so "silently", but should definitely log an ERROR message.
Should I open another ticket for this?

@jordansissel
Copy link
Contributor

I got no log message on the logstash side for this problem until I raised the level to DEBUG.

This is a lose-lose scenario. Here's the two options I've been faced with in the past:

  1. Logstash logs too much and annoys users. Annoyed users file tickets.
  2. Logstash logs too little and annoys users. Annoyed users file tickets.

Both scenarios cannot be solved simultaneously because one solution cause problems for the other.

If we make it log more by default, someone will ask me this "Why is logstash so noisy when a bad connection hits log4j input?" and we'll go back in circles.

The reason the log message is hidden by default is because there are a variety of reasons a connection could be faulty -- a network or security scan, a corrupt client, a bad network, incompatible client, unexpected data, etc.

I'm not sure how to solve "log just this specific problem where logstash has a bug in the log4j input" but also keep the corrupt client, network scan, etc from being logged by default.

@npomaroli
Copy link

Logstash logs too little and annoys users. Annoyed users file tickets.

Well, I am not annoyed but simply puzzled.

The reason the log message is hidden by default is because there are a variety of reasons a connection could be faulty -- a network or security scan, a corrupt client, a bad network, incompatible client, unexpected data, etc.

In a production environment (where I never, ever would want to set the log level to DEBUG), I would be interested in all of those reasons, why my application logs are lost.

So my only chance right now, is to make logstash really noisy.

@jordansissel
Copy link
Contributor

jordansissel commented Nov 29, 2016 via email

@BOFH90
Copy link

BOFH90 commented Dec 9, 2016

The same issue in 5.1.1 :/
If you comment it out in the now-called "logstash-core_jars.rb", it works just fine again.

@martinduris
Copy link

Confirm fix (comment out one line, logstash-core_jars.rb)

Will Logstash 5.2.0 have fix ?

@stevenwall
Copy link

This issue is impacting us as well. We would like to know what release this is going to be fixed on too.

@Free0N
Copy link

Free0N commented Jan 19, 2017

Have same trouble with 5.1.2. But when comment require_jar line in logstash-core_jars.rb catch next exception:

[root@logstash-test logstash]# bin/logstash --log.level trace --path.settings /opt/logstash/config/
NameError: missing class name (`org.apache.logging.log4j.Level')
  get_proxy_or_package_under_package at org/jruby/javasupport/JavaUtilities.java:54
                      method_missing at file:/opt/logstash-5.1.2/vendor/jruby/lib/jruby.jar!/jruby/java/java_package_module_template.rb:14
                             Logging at /opt/logstash/logstash-core/lib/logstash/logging/logger.rb:6
                            LogStash at /opt/logstash/logstash-core/lib/logstash/logging/logger.rb:5
                              (root) at /opt/logstash/logstash-core/lib/logstash/logging/logger.rb:4
                             require at org/jruby/RubyKernel.java:1040
                              (root) at /opt/logstash/logstash-core/lib/logstash/util/loggable.rb:1
                             require at org/jruby/RubyKernel.java:1040
                              (root) at /opt/logstash/logstash-core/lib/logstash/util/loggable.rb:2
                             require at org/jruby/RubyKernel.java:1040
                              (root) at /opt/logstash/logstash-core/lib/logstash/settings.rb:1
                             require at org/jruby/RubyKernel.java:1040
                              (root) at /opt/logstash/logstash-core/lib/logstash/settings.rb:2
                             require at org/jruby/RubyKernel.java:1040
                              (root) at /opt/logstash/lib/bootstrap/environment.rb:70

@jakommo
Copy link

jakommo commented Jan 26, 2017

Looks like this will be fixed by elastic/logstash#6309 which should come with 5.2.0.
@jordansissel can you confirm?

@GlenRSmith
Copy link

@jakommo It is, and checking the commit gives a more deterministic way of verifying the change was incorporated into the released branch.
elastic/logstash@69c3bc2

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

No branches or pull requests