Skip to content

Commit 06eaa88

Browse files
committed
fix: 1. Configurable timeout: postAndReply now reads AGENT_REPLY_TIMEOUT_MS env var (default 30s), with improved error message showing the timeout value
2. Double-logging fix: OrderContext.evaluate now returns Error [| e.Message |] instead of re-raising, so the error is logged once at the service level and wrapped into a Result — no second log entry from ApiImpl
1 parent c359a43 commit 06eaa88

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/Informedica.Agents.Lib/Agent.fs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,18 +278,29 @@ module Agent =
278278

279279
/// <summary>
280280
/// Posts a request to the agent and synchronously waits for a reply.
281+
/// When DefaultTimeout is Timeout.Infinite, a configurable fallback timeout is used
282+
/// (AGENT_REPLY_TIMEOUT_MS environment variable, default 30 000 ms).
281283
/// Throws if the reply times out.
282284
/// </summary>
283285
/// <param name="msg">The request message.</param>
284286
/// <param name="agent">The agent instance.</param>
285287
/// <returns>The reply value.</returns>
286288
let postAndReply msg (agent: Agent<_>) =
287289
if agent.DefaultTimeout = Timeout.Infinite then
290+
let fallbackMs =
291+
Environment.GetEnvironmentVariable("AGENT_REPLY_TIMEOUT_MS")
292+
|> Option.ofObj
293+
|> Option.bind (fun s ->
294+
match Int32.TryParse(s) with
295+
| true, v -> Some v
296+
| _ -> None
297+
)
298+
|> Option.defaultValue 30_000
288299
agent
289-
|> tryPostAndReply 30_000 msg
300+
|> tryPostAndReply fallbackMs msg
290301
|> function
291302
| Some v -> v
292-
| None -> failwith "Timed out waiting for reply"
303+
| None -> failwith $"Timed out waiting for reply after {fallbackMs} ms"
293304
else
294305
agent.PostAndReply(fun replyChannel ->
295306
msg, replyChannel

src/Informedica.GenPRES.Server/ServerApi.Services.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ module OrderContext =
350350
with
351351
| e ->
352352
writeErrorMessage $"errored:\n{e}"
353-
raise e
353+
Error [| e.Message |]
354354

355355

356356
module OrderPlan =

0 commit comments

Comments
 (0)