OmeroRequest: close resources on client.joinSession() failure #35
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As described in https://docs.oracle.com/javase/specs/jls/se8/html/jls-14.html#jls-14.20.3, a resource is closed only if it initialized to a non-null value. In the rare event of the
client.joinSession()
call throwing an exception, theOmeroRequest.close()
statement will never be invoked and clean all resources associated with thejoinSession()
. Given the current implementation of theomero.client
object, this can cause an accumulation of objects within a micro-service process which would only be cleaned up by a restart.This commit handles this scenario by catching the exception in the constructor, closing the resources and throwing a
CannotCreateSessionException
exception which is already part of the signature.Testing
Given this issue is at the
OmeroRequest
level, it will affect all micro-services and can be tested using any of them. I usedomero-ms-pixel-buffer
but these instructions can be adjusted toomero-ms-image-region
oromero-ms-thumbnail
.To look at the number of objects within the process, use
jmap -histo:live <ms_pid> | grep omero.client
.First test a regular authentication flow,
sessionid=<sessionid>
cookie associated with requested e.g. from the Developer toolsheaders
file containingCookie: sessionid=<sessionid>
locallyomero-ms-pixel-buffer
service is running. It might be useful to set https://github.com/glencoesoftware/omero-ms-pixel-buffer/blob/0d2976a7680c83e8b48c1946128c667d8632ecee/src/dist/conf/logback.xml#L21 at DEBUG leveljmap -histo:live
should not include severalomero.client
objects in memory as these should be cleaned upTo reproduce the resource leak, retrieve the OMERO session ID associated with the request. This can be done either by looking at the Blitz logs, reading and decoding the Redis key associated with the OMERO.web session or looking at the DEBUG statements in the micro-service logs (
Successfully joined session: <omerosessionid>
)omero login <omerosessionid>@localhost -w <omerosessionid> && omero logout
Permission denied
statement at DEBUG level. The output ofjmap
, there should be manyomero.client
objects in memory, as many as the number of failed requestsTo test these changes, replace the
omero-ms-core
JAR under thelib
folder of the binary with a build of this Pull Request and restart the service. Then repeat the workflow above. The behavior should be identical with the exception of the last step. The logs of the micro-service should include anERROR
level message (Failed to join session: <omerosessionid>
) and the output ofjmap -histo:live
should be identical to step 5 i.e. theomero.client
objects should no longer accumulate in memory