From ee94ad606b71480ebfbf46a06e1747edb8a7165a Mon Sep 17 00:00:00 2001 From: Berenz <5912715+akberenz@users.noreply.github.com> Date: Wed, 4 Oct 2023 14:38:00 -0400 Subject: [PATCH] perform client actions in new thread to allow pings during long running processes (#1177) --- src/qz/ws/PrintSocketClient.java | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/qz/ws/PrintSocketClient.java b/src/qz/ws/PrintSocketClient.java index ba0ea0027..567a167a6 100644 --- a/src/qz/ws/PrintSocketClient.java +++ b/src/qz/ws/PrintSocketClient.java @@ -164,20 +164,34 @@ public void onMessage(Session session, Reader reader) throws IOException { } } - processMessage(session, json, connection, request); - } - catch(UnsatisfiedLinkError | LoaderException e) { - log.error("A component is missing or broken, preventing this feature from working", e); - sendError(session, UID, "Sorry, this feature is unavailable at this time"); + //spawn thread to prevent long processes from blocking + final String tUID = UID; + new Thread(() -> { + try { + processMessage(session, json, connection, request); + } + catch(UnsatisfiedLinkError | LoaderException e) { + log.error("A component is missing or broken, preventing this feature from working", e); + sendError(session, tUID, "Sorry, this feature is unavailable at this time"); + } + catch(JSONException e) { + log.error("Bad JSON: {}", e.getMessage()); + sendError(session, tUID, e); + } + catch(InvalidPathException | FileSystemException e) { + log.error("FileIO exception occurred", e); + sendError(session, tUID, String.format("FileIO exception occurred: %s: %s", e.getClass().getSimpleName(), e.getMessage())); + } + catch(Exception e) { + log.error("Problem processing message", e); + sendError(session, tUID, e); + } + }).start(); } catch(JSONException e) { log.error("Bad JSON: {}", e.getMessage()); sendError(session, UID, e); } - catch(InvalidPathException | FileSystemException e) { - log.error("FileIO exception occurred", e); - sendError(session, UID, String.format("FileIO exception occurred: %s: %s", e.getClass().getSimpleName(), e.getMessage())); - } catch(Exception e) { log.error("Problem processing message", e); sendError(session, UID, e);