Class MatchingTimeoutExecutor


  • public final class MatchingTimeoutExecutor
    extends Object
    Shared daemon-thread executor used by request matchers (regex, XPath) to bound the runtime of pathological user-supplied expressions. Wrapping each match in a Future-with-timeout protects MockServer from ReDoS / XPath DoS attacks where a single malicious expectation or input would otherwise pin a Netty worker thread.

    The pool is cached (not single-thread) so concurrent matches do not serialize, and daemon-flagged so it never blocks JVM shutdown.

    • Method Detail

      • callWithTimeout

        public static <T> T callWithTimeout​(Callable<T> task,
                                            long timeoutMillis,
                                            T onTimeout,
                                            MatchingTimeoutExecutor.OnTimeout onTimeoutCallback)
                                     throws Exception
        Run a matching task with a millisecond timeout. A non-positive timeout disables the timeout and runs the task on the calling thread (preserving pre-timeout behaviour for users who opt out).
        Returns:
        the task's result, or onTimeout when the timeout fires
        Throws:
        Exception - any checked exception thrown by the task (other than TimeoutException)