From cb27e78271982b1ae104a6187d22f8fe3017e3cb Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Tue, 1 Oct 2019 17:49:41 +0200 Subject: [PATCH] Upgraded joni from 2.1.6 to 2.1.29 Change `Grok` class to use searchInterruptible(...) instead of search(...) otherwise we can't interrupt long running matching via the thread watch dog. Joni now also provided 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 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 b7ae54e54c3af..6fbed199b40da 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' @@ -45,10 +45,3 @@ if (isEclipse) { } } } - -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(); }