From 63b169b600886a2b049e681a13cc3d25c03b7c90 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Fri, 4 Oct 2019 12:54:49 -0500 Subject: [PATCH] Upgrade joni from 2.1.6 to 2.1.29 (#47570) Backport of #47374 Changed the Grok class to use searchInterruptible(...) instead of search(...) otherwise we can't interrupt long running matching via the thread watch dog. Joni now also provides another way to interrupt long running matches. By invoking the interrupt() method on the Matcher. We need then to refactor the watch thread dog to keep track of Matchers instead of Threads, but it is a better way of doing this, since interrupting would be more direct (not every 30k iterations) and efficient (checking a volatile field). This work needs to be done in a follow up. --- libs/grok/build.gradle | 9 +-------- libs/grok/licenses/joni-2.1.29.jar.sha1 | 1 + libs/grok/licenses/joni-2.1.6.jar.sha1 | 1 - .../src/main/java/org/elasticsearch/grok/Grok.java | 12 +++++++++--- 4 files changed, 11 insertions(+), 12 deletions(-) create mode 100644 libs/grok/licenses/joni-2.1.29.jar.sha1 delete mode 100644 libs/grok/licenses/joni-2.1.6.jar.sha1 diff --git a/libs/grok/build.gradle b/libs/grok/build.gradle index 87dc1b8b6184b..04b5a62715caa 100644 --- a/libs/grok/build.gradle +++ b/libs/grok/build.gradle @@ -18,7 +18,7 @@ */ dependencies { - compile 'org.jruby.joni:joni:2.1.6' + compile 'org.jruby.joni:joni:2.1.29' // joni dependencies: compile 'org.jruby.jcodings:jcodings:1.0.44' @@ -30,10 +30,3 @@ dependencies { forbiddenApisMain { replaceSignatureFiles 'jdk-signatures' } - -thirdPartyAudit.ignoreMissingClasses ( - // joni has AsmCompilerSupport, but that isn't being used: - 'org.objectweb.asm.ClassWriter', - 'org.objectweb.asm.MethodVisitor', - 'org.objectweb.asm.Opcodes' -) diff --git a/libs/grok/licenses/joni-2.1.29.jar.sha1 b/libs/grok/licenses/joni-2.1.29.jar.sha1 new file mode 100644 index 0000000000000..251ff2ec05a19 --- /dev/null +++ b/libs/grok/licenses/joni-2.1.29.jar.sha1 @@ -0,0 +1 @@ +3cb751702e1194ff24259155db4d37e9383d4320 \ No newline at end of file diff --git a/libs/grok/licenses/joni-2.1.6.jar.sha1 b/libs/grok/licenses/joni-2.1.6.jar.sha1 deleted file mode 100644 index 48abe138a8fd6..0000000000000 --- a/libs/grok/licenses/joni-2.1.6.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -0f23c95a06eaecbc8c74c7458a8bfd13e4fd2d3a \ No newline at end of file diff --git a/libs/grok/src/main/java/org/elasticsearch/grok/Grok.java b/libs/grok/src/main/java/org/elasticsearch/grok/Grok.java index 473e8626a4c42..07f75fd995b26 100644 --- a/libs/grok/src/main/java/org/elasticsearch/grok/Grok.java +++ b/libs/grok/src/main/java/org/elasticsearch/grok/Grok.java @@ -175,7 +175,9 @@ public String toRegex(String grokPattern) { int result; try { threadWatchdog.register(); - result = matcher.search(0, grokPatternBytes.length, Option.NONE); + result = matcher.searchInterruptible(0, grokPatternBytes.length, Option.NONE); + } catch (InterruptedException e) { + result = Matcher.INTERRUPTED; } finally { threadWatchdog.unregister(); } @@ -224,7 +226,9 @@ public boolean match(String text) { int result; try { threadWatchdog.register(); - result = matcher.search(0, text.length(), Option.DEFAULT); + result = matcher.searchInterruptible(0, text.length(), Option.DEFAULT); + } catch (InterruptedException e) { + result = Matcher.INTERRUPTED; } finally { threadWatchdog.unregister(); } @@ -244,7 +248,9 @@ public Map captures(String text) { int result; try { threadWatchdog.register(); - result = matcher.search(0, textAsBytes.length, Option.DEFAULT); + result = matcher.searchInterruptible(0, textAsBytes.length, Option.DEFAULT); + } catch (InterruptedException e) { + result = Matcher.INTERRUPTED; } finally { threadWatchdog.unregister(); }