From fdeb86510c754c914cd83e7cadccc7668374a6da Mon Sep 17 00:00:00 2001 From: Yan Chen <48968912+chenyan-dfinity@users.noreply.github.com> Date: Sun, 1 Sep 2024 10:44:18 -0700 Subject: [PATCH] fix newId race condition --- service/pool/Types.mo | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/service/pool/Types.mo b/service/pool/Types.mo index 191beb09..5e1ed16d 100644 --- a/service/pool/Types.mo +++ b/service/pool/Types.mo @@ -86,6 +86,8 @@ module { public func getExpiredCanisterId() : NewId { if (len < size) { + // increment len here to prevent race condition + len += 1; #newId } else { switch (tree.entries().next()) { @@ -124,10 +126,10 @@ module { }; public func add(info: CanisterInfo) { - if (len >= size) { + if (len > size) { assert false; }; - len += 1; + // len already incremented in getExpiredCanisterId tree.insert info; metadata.put(info.id, (info.timestamp, false)); };