diff --git a/core/src/main/java/lucee/runtime/lsp/LSPEndpointFactory.java b/core/src/main/java/lucee/runtime/lsp/LSPEndpointFactory.java index 929855354e..66a41be07f 100644 --- a/core/src/main/java/lucee/runtime/lsp/LSPEndpointFactory.java +++ b/core/src/main/java/lucee/runtime/lsp/LSPEndpointFactory.java @@ -22,6 +22,7 @@ import lucee.runtime.Component; import lucee.runtime.PageContext; import lucee.runtime.config.Config; +import lucee.runtime.engine.ThreadLocalPageContext; import lucee.runtime.exp.PageException; import lucee.runtime.op.Caster; import lucee.runtime.thread.SerializableCookie; @@ -85,7 +86,7 @@ public static LSPEndpointFactory getExistingInstance() { public Component getComponent() throws PageException, ServletException { // if component was not yet created, create it if (cfc == null && !stateless) { - cfc = engine.getCreationUtil().createComponentFromName(createPageContext(), cfcPath); + cfc = engine.getCreationUtil().createComponentFromName(createPageContext(false), cfcPath); } return cfc; } @@ -200,9 +201,12 @@ private void handleClient(Socket clientSocket) { } public String processMessage(String jsonMessage) { + PageContext previousPC = null, pc = null; try { log.info("lsp", "Received message: " + jsonMessage); - PageContext pc = createPageContext(); + // just in case there is a previous Pagcontext, safe it + previousPC = ThreadLocalPageContext.get(); + pc = createPageContext(true); if (cfc == null || stateless) { cfc = engine.getCreationUtil().createComponentFromName(pc, cfcPath); } @@ -215,6 +219,9 @@ public String processMessage(String jsonMessage) { error("lsp", e); return null; } + finally { + releasePageContext(pc, previousPC); + } } private void error(String type, Exception e) { @@ -240,13 +247,21 @@ public static Log getLog(Config config) { return null; } - public static PageContext createPageContext() throws ServletException { + public static PageContext createPageContext(boolean register) throws ServletException { return CFMLEngineFactory.getInstance().createPageContext(new File("."), "localhost", "/", "", SerializableCookie.COOKIES0, null, null, null, - DevNullOutputStream.DEV_NULL_OUTPUT_STREAM, -1, false); + DevNullOutputStream.DEV_NULL_OUTPUT_STREAM, -1, register); } - public static void releasePageContext(PageContext pc) { - CFMLEngineFactory.getInstance().releasePageContext(pc, true); + /** + * unregister temporary PageContext and register again any PageContext that was already there (just + * in case) + * + * @param pc + * @param previousPC + */ + public static void releasePageContext(PageContext pc, PageContext previousPC) { + if (pc != null) CFMLEngineFactory.getInstance().releasePageContext(pc, true); + if (previousPC != null) CFMLEngineFactory.getInstance().registerThreadPageContext(previousPC); } } \ No newline at end of file diff --git a/loader/build.xml b/loader/build.xml index 40addee0b0..ccc2aa763b 100644 --- a/loader/build.xml +++ b/loader/build.xml @@ -2,7 +2,7 @@ - + diff --git a/loader/pom.xml b/loader/pom.xml index 9e991e7b8a..f3bd1125ca 100644 --- a/loader/pom.xml +++ b/loader/pom.xml @@ -3,7 +3,7 @@ org.lucee lucee - 6.1.2.16-SNAPSHOT + 6.1.2.17-SNAPSHOT jar Lucee Loader Build