[ 
https://issues.apache.org/jira/browse/CASSANDRA-15880?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17191949#comment-17191949
 ] 

Berenguer Blasi edited comment on CASSANDRA-15880 at 9/8/20, 5:33 AM:
----------------------------------------------------------------------

Note for the reviewer: {{CompressedChunkReader.Standard}} is a 
{{RebuffererFactory}} where the main method at use is 
{{CompressedChunkReader.instantiateRebufferer()}}. That one wraps the reader in 
a {{BufferManagingRebufferer}} which will call {{close()}} and it's 
{{AutoClosable}} also. I have checked for uses of the reader in the code and as 
expected it is being closed/auto closed so I expect the {{ThreadLocal}} to be 
properly removed and not leak now.


was (Author: bereng):
Note for the reviewer: {{CompressedChunkReader.Standard}} is a 
{{RebuffererFactory}} where the main method at use is 
{{CompressedChunkReader.instantiateRebufferer()}}. That one wraps the reader in 
a {{BufferManagingRebufferer}} which will call {{close()}} and also is 
{{AutoClosable}}. I have checked for uses of the reader in the code and as 
expected it is being closed/auto closed so I expect the {{ThreadLocal}} to be 
properly removed and not leak now.

> Memory leak in CompressedChunkReader
> ------------------------------------
>
>                 Key: CASSANDRA-15880
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-15880
>             Project: Cassandra
>          Issue Type: Bug
>          Components: Feature/Compression
>            Reporter: Jaroslaw Grabowski
>            Assignee: Berenguer Blasi
>            Priority: Normal
>             Fix For: 4.0, 3.11.x
>
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> CompressedChunkReader uses java.lang.ThreadLocal to reuse ByteBuffer for 
> compressed data. ByteBuffers leak due to peculiar ThreadLocal quality.
> ThreadLocals are stored in a map, where the key is a weak reference to a 
> ThreadLocal and the value is the user's object (ByteBuffer in this case). 
> When a last strong reference to a ThreadLocal is lost, weak reference to 
> ThreadLocal (key) is removed but the value (ByteBuffer) is kept until cleaned 
> by ThreadLocal heuristic expunge mechanism. See ThreadLocal's "stale entries" 
> for details.
> When a number of long-living threads is high enough this results in thousands 
> of ByteBuffers stored as stale entries in ThreadLocals. In a not-so-lucky 
> scenario we get OutOfMemoryException.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org
For additional commands, e-mail: commits-h...@cassandra.apache.org

Reply via email to