logstash/logstash — pull request #834 by jordansissel (2013-12-05 07:17:01+00:00)
Title: Make require() threadsafe again.

Is there a unicode glyph for facepalm? Probably should be. Put it here.
Take palm. Apply to my face.

The patch for LOGSTASH-1223 had a crazy hack to work around
'require("openssl")' taking a super long time. Unfortunately, it also
made require() not threadsafe. Oops.

While poking at the problem, I found that doing
'require("shared/jruby-openssl")' before require("openssl") actually
makes it as fast without the threadsafety problem.

This commit should fix the following many bugs:
LOGSTASH-1310, LOGSTASH-1519, LOGSTASH-1325, LOGSTASH-1522

The reason 'openssl' is implicated here is because of the monkeypatch.
The common factor in user-reported problems is that using the tcp input
while also running the web interface in the same process, and tcp input
loads openssl, which does bad things and causes the web interface to
fail to load libraries it needs (like base64).

Data:
# Before this commit:
% java -jar build/*.jar irb
>> time { require("openssl") }
=> 1.763

# Without the patch for LOGSTASH-1223
% java -jar build/*.jar irb
>> time { require("openssl") }
=> 17.715

# With this change
% java -jar build/*.jar irb
>> time { require("shared/jruby-openssl"); require("openssl") }
=> 1.881

Similar performance solution without the thread safety problems.