iotaledger / iri

IOTA Reference Implementation
Other
1.15k stars 370 forks source link

Releasing the wrong key #1816

Closed GalRogozinski closed 4 years ago

GalRogozinski commented 4 years ago

Bug description

In order to release from cache we first peek, then save, then release

 private static boolean cachePersistAndReleaseNext(Tangle tangle, Cache<Indexable, TransactionViewModel> cache) throws Exception {
        Indexable hash = cache.getNextReleaseKey();
        TransactionViewModel tvm = cache.get(hash);
        if (tvm != null && tvm.shouldPersist()) {
            //We update and cache this item again so that in the case where this released item is brought back from
            // weakStore, it does not write to DB again.
            tvm.setShouldPersist(false);
            cache.put(hash, tvm);
            tangle.save(tvm.getTransaction(), hash);
        }
        return cache.releaseNext();
    }

However due to a context switches and multi-threading between peek and releaseNext() may not use the same hash 1.9.0

IRI version

1.9.0