Skip to content

[C#] ArrowStreamReader does not handle empty stream well #41110

Description

@keshen-msft

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

When input stream is empty, the reader throws exception when reading the schema, refer to

intschemaMessageLength=awaitReadMessageLengthAsync(throwOnFullRead:true,cancellationToken)
. Exception details:

System.InvalidOperationException
HResult=0x80131509
Message=Unexpectedly reached the end of the stream before a full buffer was read.
Source=Apache.Arrow
StackTrace:
at Apache.Arrow.Ipc.ArrowStreamReaderImplementation.EnsureFullRead(Memory`1 buffer, Int32 bytesRead) in /arrow/csharp/src/Apache.Arrow/Ipc/ArrowStreamReaderImplementation.cs:line 276
at Apache.Arrow.Ipc.ArrowStreamReaderImplementation.ReadMessageLength(Boolean throwOnFullRead) in /arrow/csharp/src/Apache.Arrow/Ipc/ArrowStreamReaderImplementation.cs:line 238
at Apache.Arrow.Ipc.ArrowStreamReaderImplementation.ReadSchema() in /arrow/csharp/src/Apache.Arrow/Ipc/ArrowStreamReaderImplementation.cs:line 179
at Apache.Arrow.Ipc.ArrowStreamReaderImplementation.ReadRecordBatch() in /arrow/csharp/src/Apache.Arrow/Ipc/ArrowStreamReaderImplementation.cs:line 106
at Apache.Arrow.Ipc.ArrowStreamReaderImplementation.ReadNextRecordBatch() in /arrow/csharp/src/Apache.Arrow/Ipc/ArrowStreamReaderImplementation.cs:line 53
at Apache.Arrow.Ipc.ArrowStreamReader.ReadNextRecordBatch() in /arrow/csharp/src/Apache.Arrow/Ipc/ArrowStreamReader.cs:line 107
...

On the other hand, javascript handles such input. And C++ lib also handles it, refer to https://github.com/apache/arrow/blob/cd607d00b9e3c5f2ac2a2e373ba7571fd75fc725/cpp/src/arrow/ipc/reader.cc#L1109C7-L1111C10. The behavior in javascript and C++ is that null RecordBatch is returned.

Component(s)

C#

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions