-
|
I just ran into a weird issue, I was debugging my app I noticed that as soon as I call It used to work, but stopped working some point during the day. The code iterates files on disk and processes every file: _fileNameBag
.AsParallel()
.ForAll(async fileName =>
{
ProcessTask processTask = new(
_fileNameBag,
_unknownExtensionsList,
_unknownExtensionsLock,
new FileInfo(fileName)
);
if (!await processTask.Execute())
{
_ = Interlocked.Increment(ref failedCount);
}
}); public async Task<bool> Execute()
{
if (!_processExtensions.Contains(_fileInfo.Extension.ToLower()))
{
_unknownExtensionsListLock.Enter();
if (!_unknownExtensionsList.Contains(_fileInfo.Extension.ToLower()))
{
Log.Warning("Skipping non-media file: '{FileName}'.", _fileInfo.FullName);
_unknownExtensionsList.Add(_fileInfo.Extension.ToLower());
}
_unknownExtensionsListLock.Exit();
return false;
}
// Get exiftool info
Log.Information("Running ExifTool ...");
BufferedCommandResult result = await Cli.Wrap("exiftool")
.WithArguments(["-groupNames", "-json", _fileInfo.FullName])
.ExecuteBufferedAsync();
string json = result.StandardOutput.Trim(' ', '\n', '\r', ' ', '[', ']');
Log.Information("ExifTool JSON: '{Json}'.", json);
_exifToolJson = JsonSerializer.Deserialize(
json,
SourceGenerationContext.Default.ExifToolJson
);
Debug.Assert(_exifToolJson != null, "ExifToolJson should not be null here.");
// Process files
return await DetectDoubleExtensions() // Need to manually correct
&& await RenameMixedCaseExtensions()
&& await RenameMismatchedMimeExtensions()
&& await RenamePreferredExtensions()
&& await DeleteLivePhotos()
&& await ConvertVideo()
&& await SetMissingCreateDate()
&& await DetectPcmAudio()
&& await DetectMissingCreateDate();
}I see output for If I put a breakpoint on return commandWithPipes
.ExecuteAsync(forcefulCancellationToken, gracefulCancellationToken)
.Bind(async task =>
{
try
{
var result = await task;
return new BufferedCommandResult(
result.ExitCode,
result.StartTime,
result.ExitTime,
stdOutBuffer.ToString(),
stdErrBuffer.ToString()
);
}
catch (CommandExecutionException ex)
{
throw new CommandExecutionException(
ex.Command,
ex.ExitCode,
$"""
Command execution failed, see the inner exception for details.
Standard error:
{stdErrBuffer.ToString().Trim()}
""",
ex
);
}
});Example output (note the code after CLI is never executed): This is running VSCode over SSH on a Proxmox 9 / Debian 13 host using version Any ideas? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
Are you sure |
Beta Was this translation helpful? Give feedback.
I figured out when I broke it, it was when I added
asyncin.ForAll(async fileName =>and made the lamba async.It was Rider that gave me a hint that async anonymous void returning lambda's can unexpectedly fail.
It also explains why my other projects work, as that "older" code has very few async top level functions, and the action in that code calls sync code with a return parameter.
I found this from msft.
And this experience similar to mine.