apache / apache/arrow-java

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

未關閉
#906 8 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
Type: bug
主要語言
Java
星號
94
分支
152
平均合併
3 天 16 小時
30 天內合併 PR
11

描述

### Describe the bug, including details regarding any error messages, version, and platform.

```kotlin
@Test
fun testArrowBufRetainBug() {
RootAllocator().use { al ->
val buf = al.buffer(10)
buf.close()

// correctly throws
assertThrows { 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 { 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

貢獻指南

開啟貢獻指南

研究方向

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.

由索引模型根據 Issue 內容生成。

評估

技術堆疊
java
領域
backend
Issue 類型
缺陷
難度
3/5
預估耗時
1-2 天
活躍度
停滯
描述清晰度
描述清楚
新手友好度
52/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。