From 11615aa50b3fd63f0d098f87d1c0fa4be0c930b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnter=20Obiltschnig?= Date: Fri, 9 Feb 2024 07:52:50 +0100 Subject: [PATCH] fix(OSP/JS/Web): Time out waiting for a servlet script to become available --- platform/OSP/JS/Web/src/JSServletExecutorCache.h | 5 +++++ platform/OSP/JS/Web/src/JSServletFilter.cpp | 11 ++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/platform/OSP/JS/Web/src/JSServletExecutorCache.h b/platform/OSP/JS/Web/src/JSServletExecutorCache.h index ea44fd158..e6f9be58f 100644 --- a/platform/OSP/JS/Web/src/JSServletExecutorCache.h +++ b/platform/OSP/JS/Web/src/JSServletExecutorCache.h @@ -45,6 +45,11 @@ class JSServletExecutorHolder _mutex.lock(); } + void lock(long timeout) + { + _mutex.lock(timeout); + } + void unlock() /// Unlocks access to the instance. { diff --git a/platform/OSP/JS/Web/src/JSServletFilter.cpp b/platform/OSP/JS/Web/src/JSServletFilter.cpp index 28a54a32d..4bb0cf3c7 100644 --- a/platform/OSP/JS/Web/src/JSServletFilter.cpp +++ b/platform/OSP/JS/Web/src/JSServletFilter.cpp @@ -80,7 +80,8 @@ void JSServletFilter::process(Poco::Net::HTTPServerRequest& request, Poco::Net:: if (pExecutorHolder) { cacheLock.unlock(); - Poco::ScopedLock lock(*pExecutorHolder); + long timeout = pBundle->properties().getUInt32("osp.js.jssTimeout"s, 30000); + Poco::ScopedLock lock(*pExecutorHolder, timeout); pExecutorHolder->executor()->prepareRequest(request, response); pExecutorHolder->executor()->handleRequest(request, response); } @@ -127,6 +128,14 @@ void JSServletFilter::process(Poco::Net::HTTPServerRequest& request, Poco::Net:: sendErrorResponse(response, "Script execution failed. See the server log for details."s); } } + catch (Poco::TimeoutException& exc) + { + _pContext->logger().error("Request timed out waiting for servlet script %s to become available."s, request.getURI()); + if (!response.sent()) + { + sendErrorResponse(response, "The request timed out waiting for the script to become available. See the server log for details."s); + } + } catch (Poco::Exception& exc) { _pContext->logger().log(exc);