hadoop-common-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "John Doe (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (HADOOP-15429) unsynchronized index causes DataInputByteBuffer$Buffer.read hangs
Date Mon, 30 Apr 2018 17:35:00 GMT

     [ https://issues.apache.org/jira/browse/HADOOP-15429?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

John Doe updated HADOOP-15429:
------------------------------
    Description: 
In DataInputByteBuffer$Buffer class, the fields bidx and buffers, etc are unsynchronized when
used in read() and reset() function. In certain circumstances, e.g., the reset() is invoked
in a loop, the unsynchronized bidx and buffers can trigger a concurrency bug.
Here is the code snippet.
{code:java}
    ByteBuffer[] buffers = new ByteBuffer[0];
    int bidx, pos, length;

    @Override
    public int read(byte[] b, int off, int len) {
      if (bidx >= buffers.length) {
        return -1;
      }
      int cur = 0;
      do {
        int rem = Math.min(len, buffers[bidx].remaining());
        buffers[bidx].get(b, off, rem);
        cur += rem;
        off += rem;
        len -= rem;
      } while (len > 0 && ++bidx < buffers.length); //bidx is unsynchronized
      pos += cur;
      return cur;
    }

    public void reset(ByteBuffer[] buffers) {//if one thread keeps calling reset() in a loop
      bidx = pos = length = 0;
      this.buffers = buffers;
      for (ByteBuffer b : buffers) {
        length += b.remaining();
      }
    }
{code}

  was:
In DataInputByteBuffer$Buffer class, the fields bidx and buffers, etc are unsynchronized when
used in read() and reset() function. In certain circumstances, e.g., the reset() is invoked
in a loop, the unsynchronized bidx and buffers triggers a concurrency bug.
Here is the code snippet.

{code:java}
    ByteBuffer[] buffers = new ByteBuffer[0];
    int bidx, pos, length;

    @Override
    public int read(byte[] b, int off, int len) {
      if (bidx >= buffers.length) {
        return -1;
      }
      int cur = 0;
      do {
        int rem = Math.min(len, buffers[bidx].remaining());
        buffers[bidx].get(b, off, rem);
        cur += rem;
        off += rem;
        len -= rem;
      } while (len > 0 && ++bidx < buffers.length); //bidx is unsynchronized
      pos += cur;
      return cur;
    }

    public void reset(ByteBuffer[] buffers) {//if one thread keeps calling reset() in a loop
      bidx = pos = length = 0;
      this.buffers = buffers;
      for (ByteBuffer b : buffers) {
        length += b.remaining();
      }
    }
{code}



> unsynchronized index causes DataInputByteBuffer$Buffer.read hangs
> -----------------------------------------------------------------
>
>                 Key: HADOOP-15429
>                 URL: https://issues.apache.org/jira/browse/HADOOP-15429
>             Project: Hadoop Common
>          Issue Type: Bug
>          Components: io
>    Affects Versions: 0.23.0
>            Reporter: John Doe
>            Priority: Minor
>
> In DataInputByteBuffer$Buffer class, the fields bidx and buffers, etc are unsynchronized
when used in read() and reset() function. In certain circumstances, e.g., the reset() is invoked
in a loop, the unsynchronized bidx and buffers can trigger a concurrency bug.
> Here is the code snippet.
> {code:java}
>     ByteBuffer[] buffers = new ByteBuffer[0];
>     int bidx, pos, length;
>     @Override
>     public int read(byte[] b, int off, int len) {
>       if (bidx >= buffers.length) {
>         return -1;
>       }
>       int cur = 0;
>       do {
>         int rem = Math.min(len, buffers[bidx].remaining());
>         buffers[bidx].get(b, off, rem);
>         cur += rem;
>         off += rem;
>         len -= rem;
>       } while (len > 0 && ++bidx < buffers.length); //bidx is unsynchronized
>       pos += cur;
>       return cur;
>     }
>     public void reset(ByteBuffer[] buffers) {//if one thread keeps calling reset() in
a loop
>       bidx = pos = length = 0;
>       this.buffers = buffers;
>       for (ByteBuffer b : buffers) {
>         length += b.remaining();
>       }
>     }
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org


Mime
View raw message