Open longwa opened 6 years ago
Did you end up getting traction or further info on this issue? I'm running into the exact same problem.
In my case I can get it to happen consistently when I have an optional property on my domain class that is itself another domain object. When present, that property would be lazily loaded and there are no issues, but when that property is null, the exception above occurs. I think the act of having the parent entity load the related child entity is enough to make sure the connection holder has a connection, and so the release connection code works, but if the foreign key is null, the connection holder ends up with no connection.
It seems to me that the suggestion above to simply check the if the holder has a connection before asking for it would fix this issue quite easily, but understand that it would rely on a modification to ConnectionHolder that might prove too difficult.
Fixing the issue is possible as I suggested, however, my concern is that it's just fixing the symptom and not the true issue. In fact, it might just result in pushing the issue downstream a little more.
If you have an example app that can reproduce it consistently and simply, I'd feel better about making the fix.
Thanks for commenting. I've spent a couple of hours trying to create a test case that reproduces the problem without any luck. Not surprisingly, the code base in which the problem occurs is fairly complicated, and it's hard to isolate the relevant parts. The issue occurs on background threads that are consuming messages from a queue, and there is a fairly comprehensive domain model that I'm loathe to mimic in a test case. I've managed to solve my particular issue by simply ensuring that the related domain property is never null, but I will come back to trying to create a reproducible test case when I get some free time.
Same here. We are seeing the issue in some spring batch executions which involve many moving parts including multiple threads and sessions. I’ve had a hard time reproducing on a smaller scale.
I now have a simple test case that reproduces the error
https://github.com/davidbairdala/active-connection-required-grails-bug.git
Because this bug is a bit old I might raise a new one
+1
We have the same problem with Grails 4.0.0.
In our case the problem only exists, when we use chained afterInsert methods.
Domainclass A has afterInsert that creates eight domainclasses of B and saves them (all in a service). Domainclass B has afterInsert that creates one domainclasses of C and saves it (all in a service).
In the afterInsert of A and B we use Domainclass.withNewSession{}.
The Exception is thrown after all service methods are done in the line where in domainclass A the withNewSession code starts.
Hello,
We have a large application that every once in a while hits this issue. How can we make some progress with this issue? I see there is no progress since Jan 2020. Is there anyway to get support about this issue? Ways around it?
+1 I'm also seeing this issue with Grails 4.1.2.
GORM 6.1.11.BUILD-SNAPSHOT Grails 3.3.6
We have some scenarios where using
withNewSession
can cause anActive Connection is required
error after the block executes.There are paths where the
ConnectionSynchronization.suspend
method is called and nulls out the connectionHandle on theConnectionHolder
instance that is bound.When the
GrailsHibernateTemplate.executeWithNewSession
methods cleans up in the finally block, it tries to do the following:However, in this case there IS a
connectionHolder
but it doesn't have a connection set on it. Ideally, this line should be:But
hasConnection()
isprotected
so that's not really an option. It looks like the code is already trying to cleanup and willing to ignore errors, so one solution would be to just catchIllegalArgumentException
as well asSQLException
and do the same thing.The real solution is probably to figure out the path that causes the holder to be present but still have a null connection. It definitely revolves around the
suspend
logic for transactions.I'm trying to get all the parts of a sample application together to reproduce, but I'm having trouble reproducing it in a sample application. Our particular scenario has a lot of moving parts as it's using Spring Batch, which is using some Spring AOP Transaction stuff behind the scenes along with a TaskDecorator and a few other layers.
Full Stack: