directmemory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Christoph Engelbert (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (DIRECTMEMORY-137) Concurrent access to MemoryBuffer leads to BufferUnderflowException
Date Wed, 15 Jan 2014 05:49:21 GMT

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

Christoph Engelbert edited comment on DIRECTMEMORY-137 at 1/15/14 5:48 AM:
---------------------------------------------------------------------------

A MemoryBuffer (as most other buffer, stream implementations is not threadsafe by design.
It is meant to be fast and so synchronization is bad. The correct way would be to duplicate
the buffer to have it's own writer/reader index for every access.

Let me think of this since that seems to be a general issue for all operations inside the
memorybuffer


was (Author: noctarius):
A MemoryBuffer (as most other buffer, stream implementations is not threadsafe by design.
It is meant to be fast and so synchronization is bad. The correct way would be to duplicate
the buffer to have it's own writer/reader index for every access.

> Concurrent access to MemoryBuffer leads to BufferUnderflowException
> -------------------------------------------------------------------
>
>                 Key: DIRECTMEMORY-137
>                 URL: https://issues.apache.org/jira/browse/DIRECTMEMORY-137
>             Project: Apache DirectMemory
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 0.2
>            Reporter: Chetan Mehrotra
>         Attachments: DIRECTMEMORY-137.patch
>
>
> When same MemoryBuffer is accessed by multiple thread concurrently then it can lead to
BufferUnderflowException.
> MemoryManagerService.retrieve method performs following steps
> 1. Get MemoryBuffer associated with the Pointer
> 2. Set its readerIndex to 0
> 3. Call readBytes. Which for {{NioMemoryBuffer}} invokes following code
>     @Override
>     public int readBytes( byte[] bytes, int offset, int length )
>     {
>         byteBuffer.get( bytes, offset, length );
>         readerIndex += length;
>         return length;
>     }
> So if multiple thread invoke retrieve with same Pointer then readerIndex might be set
to wrong value leading to BufferUnderflowException 
> Refer to [1] for details
> [1] http://markmail.org/thread/yvevhzddta2fyal6



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)

Mime
View raw message