Details
-
Bug
-
Status: Resolved
-
Normal
-
Resolution: Fixed
-
None
-
Correctness - Test Failure
-
Low
-
Low Hanging Fruit
-
Unit Test
-
All
-
None
-
Description
MockSchema creates SSTableReader instances for testing, but when it does, it doesn’t seem to ever close the FileHandle and Channel instances from which copies are made for the actual readers. (FileHandle itself also internally copies the channel on creation.) This can trigger leak detection, although perhaps not reliably, from tests like AntiCompactionTest. A couple well-placed try-with-resources blocks should help us avoid this (and shouldn't risk closing anything too early, since the close methods for handles and channels seem only to do reference bookkeeping anyway).
Example:
[junit-timeout] ERROR 16:35:47,747 LEAK DETECTED: a reference (org.apache.cassandra.utils.concurrent.Ref$State@487c0fdb) to class org.apache.cassandra.io.util.FileHandle$Cleanup@2072030898:/var/folders/4d/zfjs7m7s6x5_l93k33r5k6680000gn/T/mocksegmentedfile0tmp was not released before the reference was garbage collected [junit-timeout] ERROR 16:35:47,747 Allocate trace org.apache.cassandra.utils.concurrent.Ref$State@487c0fdb: [junit-timeout] Thread[main,5,main] [junit-timeout] at java.lang.Thread.getStackTrace(Thread.java:1559) [junit-timeout] at org.apache.cassandra.utils.concurrent.Ref$Debug.<init>(Ref.java:249) [junit-timeout] at org.apache.cassandra.utils.concurrent.Ref$State.<init>(Ref.java:179) [junit-timeout] at org.apache.cassandra.utils.concurrent.Ref.<init>(Ref.java:101) [junit-timeout] at org.apache.cassandra.utils.concurrent.SharedCloseableImpl.<init>(SharedCloseableImpl.java:30) [junit-timeout] at org.apache.cassandra.io.util.FileHandle.<init>(FileHandle.java:74) [junit-timeout] at org.apache.cassandra.io.util.FileHandle.<init>(FileHandle.java:50) [junit-timeout] at org.apache.cassandra.io.util.FileHandle$Builder.complete(FileHandle.java:389) [junit-timeout] at org.apache.cassandra.schema.MockSchema.sstable(MockSchema.java:124) [junit-timeout] at org.apache.cassandra.schema.MockSchema.sstable(MockSchema.java:83)