[MGNLGROOVY-157] MgnlGroovyConsole.evaluate(InputStream, String, Writer) leaks sessions Created: 20/Nov/16  Updated: 17/Mar/21  Resolved: 17/Mar/21

Status: Closed
Project: Magnolia Groovy Module
Component/s: None
Affects Version/s: 2.5
Fix Version/s: None

Type: Bug Priority: Neutral
Reporter: Jan Haderka Assignee: Unassigned
Resolution: Outdated Votes: 2
Labels: maintenance
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Date of First Response:

 Description   

Despite the fact method is now deprecated, it should close the sessions it creates, which it currently does not thus resulting in logs like:

2016-11-19 04:00:44,782 WARN org.apache.jackrabbit.core.SessionImpl : Unclosed session detected. The session was opened here: (uri:)
java.lang.Exception: Stack Trace
at org.apache.jackrabbit.core.SessionImpl.(SessionImpl.java:222)
at org.apache.jackrabbit.core.SessionImpl.(SessionImpl.java:239)
at org.apache.jackrabbit.core.XASessionImpl.(XASessionImpl.java:101)
at org.apache.jackrabbit.core.RepositoryImpl.createSessionInstance(RepositoryImpl.java:1613)
at org.apache.jackrabbit.core.RepositoryImpl.createSession(RepositoryImpl.java:956)
at org.apache.jackrabbit.core.RepositoryImpl.login(RepositoryImpl.java:1501)
at org.apache.jackrabbit.core.jndi.BindableRepository.login(BindableRepository.java:162)
at info.magnolia.repository.DefaultRepositoryManager.getSession(DefaultRepositoryManager.java:303)
at info.magnolia.context.DefaultRepositoryStrategy.internalGetSession(DefaultRepositoryStrategy.java:61)
at info.magnolia.context.AbstractRepositoryStrategy.getSession(AbstractRepositoryStrategy.java:75)
at info.magnolia.module.groovy.console.MgnlGroovyConsoleContext.getJCRSession(MgnlGroovyConsoleContext.java:138)
at info.magnolia.context.MgnlContext.getJCRSession(MgnlContext.java:664)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.__invoke(DelegatingMethodAccessorImpl.java:43)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite$StaticMetaMethodSiteNoUnwrapNoCoerce.invoke(StaticMetaMethodSite.java:148)
at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.call(StaticMetaMethodSite.java:88)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:110)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:122)
at Script1.run(Script1.groovy:14)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:589)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:627)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:598)

In case abovi is too convoluted or unclear, here's more detailed explanation:

  1. evaluate method wraps current context in MgnlGroovyConsoleContext
  2. MgnlGroovyConsoleContext overrides getRepositoryStrategy() method of AbstractContext
  3. in overridden getRepositoryStrategy() new RepositoryStrategy is created (when super class doesn't provide any (since *super* class here is the instance of newly created context, not the wrapped context)
  4. this newly created strategy is not registered nor monitored anywhere thus all the sessions created with it will be abandoned upon finishing processing of the request and left unclosed


 Comments   
Comment by Tom Wespi [ 12/Mar/17 ]

I get this error when executing a script which loads a class.

example = new ch.esense.example.ExampleClass(ctx)
example.run()

It does not seem that this error is harmful and the scripts work as expected, but the stacktraces in the log are not very nice

Comment by Jan Haderka [ 17/Mar/21 ]

Please reopen with fresh stacktrace and steps to reproduce if this is still the issue.

Generated at Mon Feb 12 05:56:09 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.