CurtHagenlocher opened a new issue, #1572:
URL: https://github.com/apache/arrow-go/issues/1572
### Describe the bug, including details regarding any error messages,
version, and platform.
I was playing with implementing the async device API in arrow-dotnet and
either this is a bug in arrow-go or I don't completely understand the
specification.
The async consumer created by `cdata.CreateAsyncDeviceStreamHandler` can
call `request()` on the `ArrowAsyncProducer` after the producer has called
`release` on the handler. The C Device Data Interface spec only requires the
producer to stay valid until release:
> [The `ArrowAsyncProducer`] _MUST_ remain valid at least until just before
calling `release` on the stream handler object.
So a conforming producer can free the `ArrowAsyncProducer` as soon as
`release` returns, and the consumer then calls a function pointer in freed
memory. This surfaced as a segfault while testing a work-in-progress .NET async
producer against arrow-go. It happens most runs with a small `queueSize`.
**Cause.** In `arrow/cdata/cdata_exports.go`:
- `(*cAsyncStreamHandler).release` (line 567) closes `taskQueue`, but tasks
already buffered in the channel can still be received.
- `asyncTaskQueue` (line 512) keeps receiving those buffered tasks after the
close (`case task, ok := <-taskQueue:`, line 519), and for each one calls
`C.goCallRequest(producer, C.int64_t(1))` (line 531) using the `producer`
pointer it captured at `on_schema` time.
The producer usually sends its last batches and then the end-of-stream task
in quick succession, followed by `release`. So the goroutine often still has
tasks buffered when release happens, and it calls `request(1)` on a producer
that may already be freed.
**To reproduce.** Use any producer that frees its `ArrowAsyncProducer` right
after calling the handler's `release` (as the spec allows), and have it produce
several batches into a handler from `CreateAsyncDeviceStreamHandler(ctx, 1,
handler)`. The process crashes with an access violation or segfault inside
`goCallRequest`. If the producer never frees the struct, the crash goes away.
**Also found while investigating:**
`asyncTaskExtract` (`arrow/cdata/exports.go`, line 311) writes through `out`
unconditionally (line 316). The spec says a consumer may pass `NULL` to
`extract_data` when it doesn't want the data ("`NULL` should be passed as the
device array pointer to indicate that the consumer doesn't want the actual
data"), so a consumer that does this crashes the Go producer.
### Component(s)
Other
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]