Like lot of the C examples, the aio copy test ignores read and write errors in the completion callback, which can cause silent data corruption. The failure in the test is not critical, but this is a bad example that may be copied by developers to a real application. The test panics now if completion callback fails, similar to other Go examples. Signed-off-by: Nir Soffer <nsoffer@redhat.com> --- golang/libnbd_590_aio_copy_test.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/golang/libnbd_590_aio_copy_test.go b/golang/libnbd_590_aio_copy_test.go index 570635c9..8be0ad2d 100644 --- a/golang/libnbd_590_aio_copy_test.go +++ b/golang/libnbd_590_aio_copy_test.go @@ -99,33 +99,41 @@ func asynch_copy(t *testing.T, src *Libnbd, dst *Libnbd) { source then do it now. */ if soff < size && src_in_flight < max_reads_in_flight { n := bs if n > size-soff { n = size - soff } buf := MakeAioBuffer(uint(n)) soff_copy := soff var optargs AioPreadOptargs optargs.CompletionCallbackSet = true - optargs.CompletionCallback = func(*int) int { + optargs.CompletionCallback = func(error *int) int { + if *error != 0 { + err := syscall.Errno(*error).Error() + panic(err) + } return read_completed(buf, soff_copy) } src.AioPread(buf, soff, &optargs) soff += n } /* If there are any write commands waiting to be issued, send them now. */ for _, wb := range writes { var optargs AioPwriteOptargs optargs.CompletionCallbackSet = true - optargs.CompletionCallback = func(*int) int { + optargs.CompletionCallback = func(error *int) int { + if *error != 0 { + err := syscall.Errno(*error).Error() + panic(err) + } return write_completed(wb.buf) } dst.AioPwrite(wb.buf, wb.offset, &optargs) } writes = writes[:0] /* Now poll the file descriptors. */ nfd := 1 sfd, err := src.AioGetFd() if err != nil { -- 2.34.1