From 5a4722374816b823f517ef47658efe02b38bc4dd Mon Sep 17 00:00:00 2001 From: Samir Talwar Date: Thu, 27 Jan 2022 15:13:45 +0100 Subject: [PATCH] ledger-on-memory: Do not create iterators on a mutable log. (#12626) 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 --- .../com/daml/ledger/on/memory/InMemoryLedgerReader.scala | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ledger/ledger-on-memory/src/main/scala/com/daml/ledger/on/memory/InMemoryLedgerReader.scala b/ledger/ledger-on-memory/src/main/scala/com/daml/ledger/on/memory/InMemoryLedgerReader.scala index 304df0496550..12e642b715a6 100644 --- a/ledger/ledger-on-memory/src/main/scala/com/daml/ledger/on/memory/InMemoryLedgerReader.scala +++ b/ledger/ledger-on-memory/src/main/scala/com/daml/ledger/on/memory/InMemoryLedgerReader.scala @@ -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, )