Skip to content

Commit

Permalink
ledger-on-memory: Do not create iterators on a mutable log. (#12626)
Browse files Browse the repository at this point in the history
We must copy the slice of the log that we are reading, to ensure that we
are not iterating over the log while we mutate it in a separate
transaction. (In other words, objects must not escape the `readLog`
function.)

This is most likely the cause of a flaky test run that we saw recently.

CHANGELOG_BEGIN
CHANGELOG_END
  • Loading branch information
SamirTalwar authored Jan 27, 2022
1 parent d2216b3 commit 5a47223
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ class InMemoryLedgerReader(
metrics.daml.ledger.log.read,
state
.readLog(
_.view.zipWithIndex.map(_.swap).slice(startExclusive + 1, endInclusive + 1)
_.view.zipWithIndex
.map(_.swap)
.slice(startExclusive + 1, endInclusive + 1)
.toVector // ensure we copy the results so we don't keep a reference to the log
)
.iterator,
)
Expand Down

0 comments on commit 5a47223

Please sign in to comment.