Skip to content

Commit

Permalink
fix newId race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyan-dfinity committed Sep 1, 2024
1 parent 17f1cb0 commit fdeb865
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions service/pool/Types.mo
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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));
};
Expand Down

0 comments on commit fdeb865

Please sign in to comment.