From 374a67c97a62e4e275971bc5ad6f2eb3f71099cb Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Tue, 9 Dec 2025 20:51:12 -0500 Subject: [PATCH] fix bounded queue: `try_pop` should drain a closed queue --- src/client/bounded_queue_sync.ml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/client/bounded_queue_sync.ml b/src/client/bounded_queue_sync.ml index f8778ea9..335a822d 100644 --- a/src/client/bounded_queue_sync.ml +++ b/src/client/bounded_queue_sync.ml @@ -47,11 +47,13 @@ end = struct let try_pop (self : 'a t) : 'a BQ.pop_result = UM.protect self.mutex @@ fun () -> - if self.closed then - `Closed - else ( - try `Item (Queue.pop self.q) with Queue.Empty -> `Empty - ) + (* first, try to pop the queue. We want to drain it even if it's closed. *) + try `Item (Queue.pop self.q) + with Queue.Empty -> + if self.closed then + `Closed + else + `Empty let push_while_not_full ~high_watermark (self : 'a t) (xs : 'a list) : push_res =