{"record":{"id":"1abb88ad71789c7d","repo":"xai-org/x-algorithm","slug":"regex-match-being-interrupted-tmeout-s","errorCode":null,"errorMessage":"regex match being interrupted. Tmeout: %s.","messagePattern":"regex match being interrupted\\. Tmeout: (.+?)\\.","errorType":"exception","errorClass":"RegexTimeoutException","httpStatus":null,"severity":"error","filePath":"botmaker/src/java/com/twitter/botmaker/compiler/InterruptibleCharSequence.java","lineNumber":26,"sourceCode":"  private long checker = 0L;\n\n  public InterruptibleCharSequence(CharSequence underlying, Timeout timeout) {\n    super();\n    this.underlying = underlying;\n    this.timeout = timeout;\n  }\n\n  @Override\n  public int length() {\n    return underlying.length();\n  }\n\n  @Override\n  public char charAt(int index) {\n\n    if ((++checker & 0x3FL) == 0) {\n      if (timeout.isDone()) {\n        throw new RegexTimeoutException(\n            String.format(\n                \"regex match being interrupted. Tmeout: %s.\", timeout\n            ));\n      }\n    }\n    return underlying.charAt(index);\n  }\n\n  @Override\n  public CharSequence subSequence(int start, int end) {\n    if (underlying instanceof InterruptibleCharSequence) {\n      return underlying.subSequence(start, end);\n    } else {\n      return new InterruptibleCharSequence(underlying.subSequence(start, end), timeout);\n    }\n  }\n\n  @Override","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/xai-org/x-algorithm/blob/24c60942c5c5fdad3a6addffb4c6e6d2f228f04f/botmaker/src/java/com/twitter/botmaker/compiler/InterruptibleCharSequence.java#L8-L44","documentation":"InterruptibleCharSequence wraps the input of a regex match and periodically (every 64 chars via the bitmask check) polls a timeout Future; if the timeout completed, the match is aborted with RegexTimeoutException. This prevents catastrophic-backtracking regexes from hanging threads.","triggerScenarios":"Running Pattern.matcher over an InterruptibleCharSequence where matching takes longer than the configured timeout — long inputs with backtracking-prone patterns (nested quantifiers, alternation overlap).","commonSituations":"User-supplied or LLM-generated regexes with catastrophic backtracking; unexpectedly large input strings after a data change; a timeout set too low for legitimate workloads.","solutions":["Simplify the regex to reduce backtracking (anchor it, remove nested quantifiers, use possessive quantifiers/atomic groups)","Increase the timeout if the match is legitimately expensive","Pre-cap input length before matching","Consider substring pre-filtering before applying the regex"],"exampleFix":"// before\nPattern p = Pattern.compile(\"(a+)+b\"); // catastrophic\n// after\nPattern p = Pattern.compile(\"a*+b|a+b\"); // possessive / simplified","handlingStrategy":"retry","validationCode":"if (input.length() > MAX_LEN) input = input.substring(0, MAX_LEN);","typeGuard":null,"tryCatchPattern":"catch (RegexTimeoutException e) { /* fall back to a simpler/safe regex or reject the input */ }","preventionTips":["Prefer anchored, linear-time regexes; avoid nested quantifiers","Cap input length before matching","Tune the timeout to your workload and monitor hit rate"],"tags":["regex","timeout","backtracking","dos-protection"],"backgroundTag":"regex-timeout","analyzedSha":"24c60942c5c5fdad3a6addffb4c6e6d2f228f04f","analyzedAt":"2026-08-28T11:40:14.686Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}