james-project icon indicating copy to clipboard operation
james-project copied to clipboard

JAMES-3724 - Fixing leak resource for MemoryMailRepository

Open vttranlina opened this issue 2 years ago • 3 comments

Fixing: Resource leaked Re-create the situation: org.apache.james.mailets.GatewayRemoteDeliveryIntegrationTest

11:48:03.733 [ERROR] o.a.j.l.a.Disposable$LeakAwareFinalizer - Leak detected! Resource org.apache.james.server.core.MimeMessageInputStreamSource$Resource@66bd8880 was not released before its referent was garbage-collected. 
This resource was instanced at: 
	org.apache.james.server.core.MimeMessageInputStreamSource#create:124
	org.apache.james.server.core.MimeMessageWrapper#<init>:156
	org.apache.james.server.core.MailImpl#setMessage:505
	com.github.fge.lambdas.consumers.ConsumerChainer#lambda$sneakyThrow$9:73
	java.util.Optional#ifPresent:183
	org.apache.james.server.core.MailImpl$Builder#build:279
	org.apache.james.server.core.MailImpl#duplicate:99
	org.apache.james.server.core.MailImpl#duplicate:810
	org.apache.james.mailrepository.memory.MemoryMailRepository#cloneMail:87
	org.apache.james.mailrepository.memory.MemoryMailRepository#store:44
	org.apache.james.transport.mailets.ToRepository#service:79
	org.apache.james.mailetcontainer.impl.ProcessorImpl#process:73
	com.github.fge.lambdas.consumers.ConsumerChainer#lambda$sneakyThrow$9:73
	java.util.stream.ForEachOps$ForEachOp$OfRef#accept:183
	java.util.stream.ReferencePipeline$2$1#accept:177
	java.util.Collections$2#tryAdvance:4747
	java.util.Collections$2#forEachRemaining:4755
	java.util.stream.AbstractPipeline#copyInto:484
	java.util.stream.AbstractPipeline#wrapAndCopyInto:474
	java.util.stream.ForEachOps$ForEachOp#evaluateSequential:150
	java.util.stream.ForEachOps$ForEachOp$OfRef#evaluateSequential:173
	java.util.stream.AbstractPipeline#evaluate:234
	java.util.stream.ReferencePipeline#forEach:497
	org.apache.james.mailetcontainer.impl.MailetProcessorImpl#executeProcessingStep:162
	org.apache.james.mailetcontainer.impl.MailetProcessorImpl#lambda$service$0:130
	java.util.stream.ReduceOps$1ReducingSink#accept:80
	java.util.Spliterators$ArraySpliterator#forEachRemaining:948
	java.util.stream.AbstractPipeline#copyInto:484
	java.util.stream.AbstractPipeline#wrapAndCopyInto:474
	java.util.stream.ReduceOps$ReduceOp#evaluateSequential:913
	java.util.stream.AbstractPipeline#evaluate:234
	java.util.stream.ReferencePipeline#reduce:563
	org.apache.james.mailetcontainer.impl.MailetProcessorImpl#service:128

vttranlina avatar Mar 28 '22 04:03 vttranlina

Regarding the Resource leak detected at MemoryMailRepositoryTest, I tried to manually dispose of resources, but then the source code of the unit test look very noisy. IMO, disabling leak detection at this test is better. It is just a unit test

vttranlina avatar Mar 28 '22 08:03 vttranlina

Many classes have been detected resource leaked. Almost come from unit-test, when it created new MailImpl for testing. Any other way is better than override detect mode everywhere?

vttranlina avatar Apr 01 '22 07:04 vttranlina

Any other way is better than override detect mode everywhere?

Patch the tests to release their resources?

chibenwa avatar Apr 01 '22 07:04 chibenwa

Is there any plan to carry on this work?

chibenwa avatar Aug 30 '22 07:08 chibenwa

Is there any plan to carry on this work?

Not yet, should we create a Jira task, then add it to the backlog, and close this pr?

vttranlina avatar Sep 07 '22 04:09 vttranlina

We already have JIRAs for this topic.

chibenwa avatar Sep 07 '22 06:09 chibenwa