-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
This issue is related to the input size, so I provided an example test.txt file with a length where the issue triggers. If the stdin.add() is used with multiple smaller chunks sometimes I can get it to write the whole file out, sometimes only the multiples of the chunk size is written out and the last chunk is missing.
Code to reproduce:
import 'dart:io';
import 'dart:typed_data';
import 'package:path/path.dart';
final String workdir = dirname(Platform.script.toFilePath());
Future<int> main(List<String> arguments) async {
final Uint8List bytes = File('$workdir/test.txt').readAsBytesSync();
final Process proc = await Process.start(
'dart',
<String>[
'$workdir/writetofile.dart',
'debug.bin',
],
runInShell: true,
workingDirectory: workdir,
);
proc.stdin.add(bytes);
stdout.addStream(proc.stdout);
stderr.addStream(proc.stderr);
await proc.stdin.flush();
await proc.stdin.close();
return 0;
}
Support script to write stdin to file the above script calls:
import 'dart:io';
Future<int> main(List<String> arguments) async {
final File outputFile = File(arguments[0]);
outputFile.createSync();
final IOSink output = outputFile.openWrite();
await output.addStream(stdin);
await output.flush();
await output.close();
return 0;
}
The test input file:
test.txt
Expected: The newly created debug.bin file has the exact same size the source test.txt file has.
Actual: The newly created debug.bin file has zero size.
Dart version: Dart SDK version: 2.18.6 (stable) (Tue Dec 13 21:15:14 2022 +0000) on "windows_x64"
Platform: Windows
Edit: The issue came from working with ProcessPools and WorkerJobs. The ProcessPool uses LocalProcessManager by default, which uses Process.start() and feeds the stdin asynchronously.