When UnrestrictedSessionRunner is used to fetch Documents, these documents are associated with the unrestricted session.
This is the very reason why, an UnrestrictedSessionRunner should never return live Documents.
However, we sometimes have the requirement to do so : EasyShare plugin is a good exemple.
Typically :
- the interactive user is not authenticated
- we use UnrestrictedSessionRunner to fetch documents
- we then use a FreeMarker template to display content
The problem is that the template rendering may trigger lazy-loading on the DocumentModel that will then try to access the session that has been closed previously.
To avoid that issue, there are basicaly 2 options :
Disconnect Documents
The UnrestrictedSessionRunner implementation could disconned all Documents before returning them
Sync session close with rendering closing
This is what was done in the initial implementation.
https://github.com/mobrebski/nuxeo-easyshare/blob/14ec509c9eca1faa2bfc01ebfc06d9c883a6cad1/src/main/java/org/nuxeo/easyshare/EasyShareUnrestrictedRunner.java
Unfortunately, this forces the implementer to override a lot of code or to copy a lot of code.
A better solution would be to make the cleanup method pluggable.
- depends on
-
NXP-14140 Make CoreSession thread-safe
- Resolved