zeroshade opened a new pull request, #1410:
URL: https://github.com/apache/arrow-go/pull/1410
### Rationale for this change
`TestCallFunctionPreservesCallerCancellationForVectorFunction` fails
intermittently under `-race` (e.g. ARM64 macOS 14 Go 1.26 - CGO on #1406):
```
--- FAIL: TestCallFunctionPreservesCallerCancellationForVectorFunction
exec_test.go:385: Expected nil, but got: &compute.ArrayDatum{...}
```
It is a real race, not a test problem: a cancelled `CallFunction` can return
a result with a nil error.
- The kernel gets the **caller's** context: `kctx := &exec.KernelCtx{Ctx:
ctx, ...}` in `execInternal`.
- `execInternal` then derives a **child** context
(`context.WithCancel(ctx)`), and every cancellation check after that
(`WrapResults`, and the `ctx.Err()` check after it) uses the child.
- Cancelling a context closes its `Done` channel *before* cancelling its
children. In that gap the kernel can wake on the caller's cancellation, return,
and the executor can send its output and close the channel; `WrapResults` then
collects the output while the child context still reports no error, and
`execInternal` returns it.
On main, running that test 20,000 times under `-race` fails 15 times.
### What changes are included in this PR?
`execInternal` keeps a reference to the caller's context and, after
`WrapResults`, treats the call as cancelled if either the caller's or the child
context is done. The returned error is the caller's cancellation cause when the
caller cancelled, otherwise the child's (unchanged). The kernel, executors and
`WrapResults` are unchanged.
### Are these changes tested?
By the existing
`TestCallFunctionPreservesCallerCancellationForVectorFunction` (and its scalar
counterpart), which is the regression test for this race:
- main: 15 failures in 20,000 runs under `-race`;
- this PR: 0 failures in 20,000 runs under `-race`.
`go test ./arrow/compute/...` and `go test -race ./arrow/compute` pass; `go
vet` (with `-asmdecl=false -framepointer=false` for the existing assembly
warnings) and `gofmt` are clean.
### Are there any user-facing changes?
Yes: a cancelled compute call no longer occasionally returns a result with a
nil error. No API changes.
--
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]