Turns out that we already double insert into the loader: when two requests to load a module come in at the same time, both will find the loaded and compiled module caches empty, so both will start the process of verifying the module and insert it. The last write wins, and the older write's binaries entry leaks.
Removing the invariant violation check, and accepting that we will sometimes leak entries as the alternative is to hold the lock for longer in the critical path, which will be too detrimental for performance.
Test Plan
$ cargo nextest
Run the Sui-specific stress-test benchmark that uncovered this issue.
Turns out that we already double insert into the loader: when two requests to load a module come in at the same time, both will find the loaded and compiled module caches empty, so both will start the process of verifying the module and insert it. The last write wins, and the older write's
binaries
entry leaks.Removing the invariant violation check, and accepting that we will sometimes leak entries as the alternative is to hold the lock for longer in the critical path, which will be too detrimental for performance.
Test Plan