AynSiddiqui opened a new pull request, #1609:
URL: https://github.com/apache/arrow-go/pull/1609

   ### Rationale for this change
   
   Fixes #1572.
   
   The spec only requires an `ArrowAsyncProducer` to stay valid until just 
before the producer calls `release` on the handler. The handler from 
`CreateAsyncDeviceStreamHandler` can still have tasks queued at that point, and 
`asyncTaskQueue` called `request(1)` on the producer for each of them, so a 
producer that frees itself after `release`, like the .NET producer in the 
issue, could still be called.
   
   Separately, `asyncTaskExtract` wrote through `out` without a NULL check, 
although the spec lets a consumer pass NULL when it doesn't want the data.
   
   ### What changes are included in this PR?
   
   - `cAsyncStreamHandler` guards `producer` with a mutex. `release` clears it, 
and `asyncTaskQueue` now takes the handler and calls `request` and `cancel` 
only while `producer` is set. Tasks that were already queued are still 
extracted as before; only the calls into the producer stop.
   - `asyncTaskExtract` returns 0 without writing when `out` is NULL. The 
record is still released.
   
   `release` now waits while a `request` or `cancel` call from the consumer is 
in progress. The spec asks producers not to call `release` from inside 
`request` while not cancelled, so that path doesn't re-enter. A producer that 
holds its own lock while calling `release` and takes the same lock in `request` 
or `cancel` could block here. I didn't see a way to drop the wait without 
calling a producer that may already be gone, but I'm open to another approach.
   
   ### Are these changes tested?
   
   Yes, two tests in `arrow/cdata/cdata_test.go` with helpers in 
`cdata_test_framework.go`:
   
   - `TestAsyncNoRequestAfterRelease`: a C producer sends three tasks and the 
end of the stream, then calls `release`. Its `extract_data` waits until 
`release` has returned, so at least two tasks are still queued when the handler 
is released. The test counts `request` calls made after `release` returns and 
checks that `extract_data` is called for all three tasks. On main it fails in 
10 of 10 runs; with this change no `request` call is made after `release`.
   - `TestAsyncTaskExtractNull`: calls `asyncTaskExtract` with a NULL `out` 
using a checked allocator. On main it panics with a nil pointer dereference; 
here it returns 0 and the checked allocator reports no outstanding allocations.
   
   `go test -tags test,assert -short ./arrow/cdata/...`, the same with `noasm`, 
`go test -race -tags test -count=20 -run TestAsync ./arrow/cdata/` and 
`golangci-lint run ./arrow/cdata/...` pass on Linux amd64 with Go 1.27.1. I 
didn't run the full module tests or test against a real external producer.
   
   ### Are there any user-facing changes?
   
   No API changes. A producer can now free its `ArrowAsyncProducer` after 
calling `release` without the consumer calling into it, and consumers can pass 
NULL to `extract_data`.
   


-- 
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]

Reply via email to