From b0f93b98c93bd7392f742a2794ceedf89fc8da8e Mon Sep 17 00:00:00 2001 From: Victor Allombert Date: Wed, 17 Dec 2025 08:40:08 +0100 Subject: [PATCH 1/2] Lib_bees/Hive: limit lwt_tasks_stream size --- src/lib_bees/hive.ml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lib_bees/hive.ml b/src/lib_bees/hive.ml index 22cd0c549958..3d76a9bed7ee 100644 --- a/src/lib_bees/hive.ml +++ b/src/lib_bees/hive.ml @@ -37,10 +37,16 @@ type t = { lwt_tasks_stream : (unit -> unit Lwt.t) Eio.Stream.t; } +(* This arbitrary value aims to limit the number of elements that can be + accumulated in the [lwt_tasks_stream] closure buffer. The upper bound is not + expected to be reached but it is set to high value to avoid Eio.Stream.push + to be blocking if reached at some point. *) +let tasks_stream_max_size = 16_384 + let hive = { workers = WorkerTbl.create ~initial_size:64; - lwt_tasks_stream = Eio.Stream.create max_int; + lwt_tasks_stream = Eio.Stream.create tasks_stream_max_size; } let async_lwt = Eio.Stream.add hive.lwt_tasks_stream -- GitLab From 6a1c2920060d91a1a84c348bccd2c6555896f6d9 Mon Sep 17 00:00:00 2001 From: Victor Allombert Date: Wed, 17 Dec 2025 10:25:49 +0100 Subject: [PATCH 2/2] Lib_bees/Hive: Add warning regarding async_lwt calls --- src/lib_bees/hive.mli | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib_bees/hive.mli b/src/lib_bees/hive.mli index 598f0b2a4de2..a953bf9faa21 100644 --- a/src/lib_bees/hive.mli +++ b/src/lib_bees/hive.mli @@ -35,7 +35,11 @@ val get_error : string -> exn option If the closure raises an exception, it will break the internal lwt loop and prevent any subsequent asynchronous call to be executed. It's consequently advised to handle exceptions directly in the closure and return - a [result]. *) + a [result]. + + Warning: Promises added to this loop are expected to perform only very short + computations (typically just sending events). Longer computations may + congest promise scheduling and cause blocking [async_lwt] calls.*) val async_lwt : (unit -> unit Lwt.t) -> unit (** Schedule [f] to run on the Event_loop main switch and return its result. -- GitLab