dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.37k stars 4.75k forks source link

[browser][io][tests] Failure: System.IO.Tests file for 2GB file reads #45954

Open kjpou1 opened 3 years ago

kjpou1 commented 3 years ago

64 bit numbers could be the culprit here as it seems to stand out.

            at Object.get64 (http://127.0.0.1:54025/dotnet.js:4354:14) 

The tests are failing with the following:


[03:50:20] fail: [FAIL] System.IO.Tests.File_ReadWriteAllBytes.ReadFileOver2GB
[03:50:20] info: System.IO.IOException : Invalid argument
[03:50:20] info:    at System.IO.FileStream.CheckFileCall(Int64 result, Boolean ignoreNotSupported)
[03:50:20] info:    at System.IO.FileStream.CheckFileCall(Int32 result, Boolean ignoreNotSupported)
[03:50:20] info:    at System.IO.FileStream.SetLengthInternal(Int64 value)
[03:50:20] info:    at System.IO.FileStream.SetLength(Int64 value)
[03:50:20] info:    at System.IO.Tests.File_ReadWriteAllBytes.ReadFileOver2GB()
[03:50:20] info:    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
[03:50:21] fail: [FAIL] System.IO.Tests.File_ReadWriteAllBytesAsync.ReadFileOver2GBAsync
[03:50:21] info: System.IO.IOException : Invalid argument
[03:50:21] info:    at System.IO.FileStream.CheckFileCall(Int64 result, Boolean ignoreNotSupported)
[03:50:21] info:    at System.IO.FileStream.CheckFileCall(Int32 result, Boolean ignoreNotSupported)
[03:50:21] info:    at System.IO.FileStream.SetLengthInternal(Int64 value)
[03:50:21] info:    at System.IO.FileStream.SetLength(Int64 value)
[03:50:21] info:    at System.IO.Tests.File_ReadWriteAllBytesAsync.ReadFileOver2GBAsync()
info: ABORT: Assertion failed: undefined
  info: Stacktrace:
  info: Error
            at Object.onAbort (http://127.0.0.1:54025/runtime.js:210:13)
            at abort (http://127.0.0.1:54025/dotnet.js:1389:22)
            at assert (http://127.0.0.1:54025/dotnet.js:588:5)
            at Object.get64 (http://127.0.0.1:54025/dotnet.js:4354:14)
            at ___sys_ftruncate64 (http://127.0.0.1:54025/dotnet.js:4472:29)
            at ftruncate (http://127.0.0.1:54025/dotnet.wasm:wasm-function[15944]:0x2faa12)
            at SystemNative_FTruncate (http://127.0.0.1:54025/dotnet.wasm:wasm-function[7758]:0x22368c)
            at wasm_invoke_iil (http://127.0.0.1:54025/dotnet.wasm:wasm-function[7269]:0x20465b)
            at ves_pinvoke_method (http://127.0.0.1:54025/dotnet.wasm:wasm-function[190]:0x2920a)
            at interp_exec_method (http://127.0.0.1:54025/dotnet.wasm:wasm-function[137]:0xb658)
  info: WASM EXIT 1

See PR: https://github.com/dotnet/runtime/pull/45949

adamsitnik commented 3 years ago

I've hit this limitation when I was working on #60459 earlier today. It seems that large files > 2 GB are simply not supported by WASM.

Sample tests:

```cs [Fact] public void LargeFilesAreSupported() { const long positon = int.MaxValue + 1L; string filePath = GetTestFilePath(); byte[] data = { 1, 2, 3, 4, 5 }; using (var stream = new FileStream(filePath, FileMode.Create, FileAccess.Write)) { stream.Seek(positon, SeekOrigin.Begin); stream.Write(data); Assert.Equal(positon + data.Length, stream.Position); Assert.Equal(positon + data.Length, stream.Length); } } ```

Fails with:

```log fail: [FAIL] System.IO.Tests.FileStream_Read.LargeFilesAreSupported info: System.IO.IOException : Invalid argument : '/tmp/FileStream_Read_f42bzuwo.p40/LargeFilesAreSupported_70_2a38023c' info: at System.IO.Strategies.FileStreamHelpers.CheckFileCall(Int64 result, String path, Boolean ignoreNotSupported) in /home/adam/projects/runtime/src/libraries/System.Private.CoreLib/src/System/IO/Strategies/FileStreamHelpers.Unix.cs:line 24 info: at System.IO.RandomAccess.WriteAtOffset(SafeFileHandle handle, ReadOnlySpan`1 buffer, Int64 fileOffset) in /home/adam/projects/runtime/src/libraries/System.Private.CoreLib/src/System/IO/RandomAccess.Unix.cs:line 138 info: at System.IO.Strategies.OSFileStreamStrategy.Write(ReadOnlySpan`1 buffer) in /home/adam/projects/runtime/src/libraries/System.Private.CoreLib/src/System/IO/Strategies/OSFileStreamStrategy.cs:line 282 info: at System.IO.Strategies.OSFileStreamStrategy.Write(Byte[] buffer, Int32 offset, Int32 count) in /home/adam/projects/runtime/src/libraries/System.Private.CoreLib/src/System/IO/Strategies/OSFileStreamStrategy.cs:line 269 info: at System.IO.Strategies.BufferedFileStreamStrategy.FlushWrite() in /home/adam/projects/runtime/src/libraries/System.Private.CoreLib/src/System/IO/Strategies/BufferedFileStreamStrategy.cs:line 1020 info: at System.IO.Strategies.BufferedFileStreamStrategy.Flush(Boolean flushToDisk) in /home/adam/projects/runtime/src/libraries/System.Private.CoreLib/src/System/IO/Strategies/BufferedFileStreamStrategy.cs:line 804 info: at System.IO.Strategies.BufferedFileStreamStrategy.Flush() in /home/adam/projects/runtime/src/libraries/System.Private.CoreLib/src/System/IO/Strategies/BufferedFileStreamStrategy.cs:line 790 info: at System.IO.Strategies.BufferedFileStreamStrategy.Dispose(Boolean disposing) in /home/adam/projects/runtime/src/libraries/System.Private.CoreLib/src/System/IO/Strategies/BufferedFileStreamStrategy.cs:line 150 info: at System.IO.Strategies.BufferedFileStreamStrategy.DisposeInternal(Boolean disposing) in /home/adam/projects/runtime/src/libraries/System.Private.CoreLib/src/System/IO/Strategies/BufferedFileStreamStrategy.cs:line 140 info: at System.IO.FileStream.Dispose(Boolean disposing) in /home/adam/projects/runtime/src/libraries/System.Private.CoreLib/src/System/IO/FileStream.cs:line 499 info: at System.IO.Stream.Close() in /home/adam/projects/runtime/src/libraries/System.Private.CoreLib/src/System/IO/Stream.cs:line 165 info: at System.IO.Stream.Dispose() in /home/adam/projects/runtime/src/libraries/System.Private.CoreLib/src/System/IO/Stream.cs:line 158 info: at System.IO.Tests.FileStream_Read.LargeFilesAreSupported() in /home/adam/projects/runtime/src/libraries/System.IO.FileSystem/tests/FileStream/Read.cs:line 80 info: at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) in /home/adam/projects/runtime/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs:line 370 info: Finished: System.IO.FileSystem.Tests.dll ```

@SamMonoRT @lewing @vargaz are we aware of that? I am asking because the info provided above may suggest that only SetLength does not work, while simply nothing works for such files.

pavelsavara commented 1 year ago

Related https://github.com/dotnet/runtime/issues/45954