Skip to content

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

@jarohen

Description

@jarohen

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions