BUG? -- MS SQL Server JDBC 13.2.1 with lucee.datasource.mssql.modern=true

Set up:
Lucee version 6.2.2.91 but has also been seen with 6.2.3.35
Microsoft SQL Server JDBC Driver 13.2.1
lucee.datasource.mssql.modern=true
or
LUCEE_DATASOURCE_MSSQL_MODERN=true

The follow query produces an error with the latest MS SQL jdbc driver and when the code path protected by lucee.datasource.mssql.modern=true is enabled.

The exception shown (full exception below):
lucee.runtime.exp.DatabaseException: The result set is closed. at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:250)

The issues at lucee.runtime.type.QueryImpl.fillResult(QueryImpl.java:626) seems to point to the new driver not allowing result.getMetaData() to be called on a closed ResultSet.

<!--- Minimal test cases seems to need to have a parameterized query, set a reference for the result, and then attempt to access the result --->
<cfscript>
    function getsqlobj(objectId) {
        var getObj = QueryExecute(
            "SELECT TOP 10 name FROM sys.objects where object_id > :objectId",
            {objectId: {value: objectId, cfsqltype: "CF_SQL_INTEGER"}},
            {datasource: Application.DSN, result: "testResult"}
        );
        return {query: getObj, result: testResult};
    }
</cfscript>
<cfdump var="#getsqlobj(5)#">

There are other variations such as using the new Query() cfc that does something internal that always causes the exception.

Version 6.2.2.91 stacktrace:

lucee.runtime.exp.DatabaseException: The result set is closed. at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:250) at com.microsoft.sqlserver.jdbc.SQLServerResultSet.checkClosed(SQLServerResultSet.java:496) at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getMetaData(SQLServerResultSet.java:2421) at lucee.runtime.type.QueryImpl.fillResult(QueryImpl.java:626) at lucee.runtime.type.QueryImpl.(QueryImpl.java:209) at lucee.runtime.type.QueryImpl.setGeneratedKeys(QueryImpl.java:554) at lucee.runtime.type.QueryImpl.executeMSSQL(QueryImpl.java:429) at lucee.runtime.type.QueryImpl.execute(QueryImpl.java:263) at lucee.runtime.type.QueryImpl.(QueryImpl.java:239) at lucee.runtime.tag.Query.executeDatasoure(Query.java:1125) at lucee.runtime.tag.Query._doEndTag(Query.java:692) at lucee.runtime.tag.Query.doEndTag(Query.java:557) at lucee.runtime.functions.query.QueryExecute.call(QueryExecute.java:86) at onehit.colbyttest_tbd_cfm$cf.udfCall(/OneHit/colbytTest_TBD.cfm:41) at lucee.runtime.type.UDFImpl.implementation(UDFImpl.java:112) at lucee.runtime.type.UDFImpl._call(UDFImpl.java:357) at lucee.runtime.type.UDFImpl.call(UDFImpl.java:224) at lucee.runtime.type.scope.UndefinedImpl.call(UndefinedImpl.java:811) at lucee.runtime.util.VariableUtilImpl.callFunctionWithoutNamedValues(VariableUtilImpl.java:773) at lucee.runtime.PageContextImpl.getFunction(PageContextImpl.java:2081) at onehit.colbyttest_tbd_cfm$cf.call(/OneHit/colbytTest_TBD.cfm:45) at lucee.runtime.PageContextImpl._doInclude(PageContextImpl.java:1118) at lucee.runtime.PageContextImpl._doInclude(PageContextImpl.java:1012) at lucee.runtime.listener.ModernAppListener._onRequest(ModernAppListener.java:213) at lucee.runtime.listener.MixedAppListener.onRequest(MixedAppListener.java:41) at lucee.runtime.PageContextImpl.execute(PageContextImpl.java:2816) at lucee.runtime.PageContextImpl._execute(PageContextImpl.java:2803) at lucee.runtime.PageContextImpl.executeCFML(PageContextImpl.java:2774) at lucee.runtime.engine.Request.exe(Request.java:45) at lucee.runtime.engine.CFMLEngineImpl._service(CFMLEngineImpl.java:1113) at lucee.runtime.engine.CFMLEngineImpl.serviceCFML(CFMLEngineImpl.java:1070) at lucee.loader.engine.CFMLEngineWrapper.serviceCFML(CFMLEngineWrapper.java:97) at lucee.loader.servlet.jakarta.CFMLServlet.service(CFMLServlet.java:52) at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:658) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:195) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:167) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:90) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:483) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:116) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:93) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:732) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:344) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:398) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:903) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1769) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52) at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1189) at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:658) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:63) at java.base/java.lang.Thread.run(Thread.java:840) Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The result set is closed. … 56 more

what was the previous jdbc version which worked?

I’m having a look

https://luceeserver.atlassian.net/browse/LDEV-5970

1 Like

It was working with 12.6.3.jre11 and likely quite a few other older versions, some of this code is really old.

ok, interesting bug!

this modern mssql support was always a bit hacky, which triggered this bug

after some research around the web, i figured out a nice solution which both solves the issue and makes this more robust/ efficient / faster

image

This afternoon (now very late tonight, 1.57am here in Berlin) ended up being a fix a lot of database issues day!

https://luceeserver.atlassian.net/browse/LDEV-5972

try 7.0.2.8 or 6.2.5.7 SNAPSHOTs

Also added some documentation

1 Like

I’m running into this issue as well. The newer versions do appear to resolve the issues.

Is there an ETA on when stable versions of 6 and 7 will be released that contain this bug fix?

Official RCs coming up soon for both, just got one more blocker with classloading memory issues.

The only difference between a SNAPSHOT and a RC, is 6 characters in the version :slight_smile: I know that doesn’t help with official company policies

What does help moving RCs into Stable Releases is good feedback like this tho! thanks!

Is there a ticket for the Class Loader issue that’s a blocker (and does that affect Lucee 6 and 7 or just 7)?

I know our app appears to have lots of issues in Lucee 7 and I’ve seen some very weird performance issues in 7, which I think might be class loader related, but haven’t dug into it yet (but will later today).

I can get our unit tests to pass in Lucee 6 with the latest snapshot, but it does not work in the official release due to this issue.

This is the ticket

https://luceeserver.atlassian.net/browse/LDEV-5903

Like all bugs, actual lack of a repo always really hinders getting it fixed, we always try to reduce a more complicated provided example down to the bare minimum… The Lucee team often spends more time triaging and producing tests than actually solving the problems!

That said, if you are testing locally, enabling a JFR recording is a great way to investigate problems

Thanks!

If I run into this issue, I’ll see if I can produce a repo.

Having read the comments in the issue, these are always tricky problems because the cause probably involves several weird things happening at once and that’s often difficult to track down in order to provide a simple repo.

this one took ages to figure out…

https://luceeserver.atlassian.net/browse/LDEV-6056

keep in mind, JFR has some overhead (it’s better with java 25)

The following will give you very detailed jfr logs, LLMs like Claude Code are quite good at querying them using the jfr cli tool for things like exceptions, locking, etc

jfc-high-frequency.jfc (3.1 KB)

-XX:StartFlightRecording=disk=true,dumponexit=true,filename=/path/to/log-file.jfr,maxsize=1024m,maxage=1d,settings=/path/to/jfc-high-frequency.jfc,path-to-gc-roots=true

You really don’t need the CompilerInlining, CompilerPhase, Deoptimization or Compilation options enabled, that’s just some of the crazy in depth, hardcore shit I’ve been use for tuning Lucee internals, been using that for some good improvements upcoming up with 7.1

There’s lot of related stuff which shows up with that in 7.0 which is solved in 7.1 and the pending PRs