From 6d4433add378ae3d2516c93775ef5edb1679ab57 Mon Sep 17 00:00:00 2001 From: Manan Bhatt Date: Tue, 5 May 2026 17:16:26 +0000 Subject: [PATCH] fix: async void -> async Task, and TotalMilliseconds in Sleep log MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug 2: WorkOnce, ProcessTasks, and ProcessTask were declared as `private async void`, which swallows exceptions — they are fire-and-forget and callers cannot await them. Changed all three to `private async Task` so exceptions propagate correctly. Work4Ever now calls WorkOnce(...).GetAwaiter().GetResult() to stay synchronous at the top-level loop. Bug 3: The Sleep() log message used timeSpan.Milliseconds (the subsecond component, range 0-999) instead of timeSpan.TotalMilliseconds (the full duration as a double). Any sleep >= 1 second would log 0ms or an incorrect truncated value. Fixed to use TotalMilliseconds. --- Conductor/Client/Worker/WorkflowTaskExecutor.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Conductor/Client/Worker/WorkflowTaskExecutor.cs b/Conductor/Client/Worker/WorkflowTaskExecutor.cs index 180a4c35..fc877195 100644 --- a/Conductor/Client/Worker/WorkflowTaskExecutor.cs +++ b/Conductor/Client/Worker/WorkflowTaskExecutor.cs @@ -1,4 +1,4 @@ -/* +/* * Copyright 2024 Conductor Authors. *

* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with @@ -93,7 +93,7 @@ private void Work4Ever(CancellationToken token) if (token != CancellationToken.None) token.ThrowIfCancellationRequested(); - WorkOnce(token); + WorkOnce(token).GetAwaiter().GetResult(); } catch (System.OperationCanceledException canceledException) { @@ -120,7 +120,7 @@ private void Work4Ever(CancellationToken token) } } - private async void WorkOnce(CancellationToken token) + private async System.Threading.Tasks.Task WorkOnce(CancellationToken token) { if (token != CancellationToken.None) token.ThrowIfCancellationRequested(); @@ -201,7 +201,7 @@ private async void WorkOnce(CancellationToken token) } } - private async void ProcessTasks(List tasks, CancellationToken token) + private async System.Threading.Tasks.Task ProcessTasks(List tasks, CancellationToken token) { List threads = new List(); if (tasks == null || tasks.Count == 0) @@ -221,7 +221,7 @@ private async void ProcessTasks(List tasks, CancellationToken token await System.Threading.Tasks.Task.WhenAll(threads); } - private async void ProcessTask(Models.Task task, CancellationToken token) + private async System.Threading.Tasks.Task ProcessTask(Models.Task task, CancellationToken token) { if (token != CancellationToken.None) token.ThrowIfCancellationRequested(); @@ -341,7 +341,7 @@ private void RecordTaskResultSize(Models.TaskResult taskResult) private void Sleep(TimeSpan timeSpan) { - _logger.LogDebug($"[{_workerSettings.WorkerId}] Sleeping for {timeSpan.Milliseconds}ms"); + _logger.LogDebug($"[{_workerSettings.WorkerId}] Sleeping for {timeSpan.TotalMilliseconds}ms"); Thread.Sleep(timeSpan); } @@ -349,4 +349,4 @@ private void LogInfo() { } } -} \ No newline at end of file +}