Calling `retain` on a closed ArrowBuf revives it, into an undefined state

Open
#906 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
52/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
java
Domain
backend

Research direction

Start at BufferLedger.retain(int), where the issue identifies getAndAdd as the source of the incorrect positive reference count. Run the provided testArrowBufRetainBug reproduction and verify that closing the buffer leaves refCnt() at 0 and that subsequent retain() calls still throw IllegalArgumentException.

Written by the indexing model from the issue text.

Description

Type: bug
Describe the bug, including details regarding any error messages, version, and platform.
@Test
fun testArrowBufRetainBug() {
    RootAllocator().use { al ->
        val buf = al.buffer(10)
        buf.close()

        // correctly throws
        assertThrows<IllegalArgumentException> { buf.referenceManager.retain() }

        assertEquals(0, buf.refCnt()) // nope, it's 1

        // doesn't throw, ref-count is 1 - so the caller assumes they've successfully taken a reference
        // but the underlying memory has already been reclaimed and re-used
        assertThrows<IllegalArgumentException> { buf.referenceManager.retain() }
    }
}

Caused by the getAndAdd in BufferLedger.retain(int) - this is what leaves the ref-count positive, so on the next call, this doesn't fail.

Some kind of compareAndSet instead, perhaps?

Cheers,

James

Dominant language
Java
Stars
95
Forks
154
Avg merge
2d 10h
Merged PRs (30d)
11

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apache/arrow-java

All issues in apache/arrow-java

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.