Commit c4ee110
Fix storage cache reads dropping Arc before use (linera-io#6046)
## Motivation
After linera-io#5967 introduced Arc-shared caches with weak-index deduplication,
several DbStorage read methods (read_confirmed_block, read_blob,
read_event, etc.) used an insert-then-get pattern:
```rust
self.caches.confirmed_block.insert(&hash, block);
Ok(self.caches.confirmed_block.get(&hash))
```
The Arc returned by insert is dropped immediately. If the bounded cache
(S3-FIFO) evicts the entry before get runs -- e.g., under high cache
pressure or concurrent inserts -- and no other consumer holds a strong
reference, the weak index entry becomes dead and get returns None. This
turns a successful DB read into a spurious None, causing errors like
`Missing confirmed block` in the chain listener.
## Proposal
Use the Arc returned by insert directly instead of round-tripping
through get:
```rust
Ok(Some(self.caches.confirmed_block.insert(&hash, block)))
```
Fixed in 5 call sites:
- read_confirmed_block
- read_confirmed_blocks
- read_blob
- read_certificates_raw
- read_event
## Test Plan
- Existing CI tests pass
- Verified no other insert-then-get pattern exists
(insert_hashed/get_hashed callers do not use this pattern)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 0147e65 commit c4ee110
1 file changed
Lines changed: 13 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
775 | 775 | | |
776 | 776 | | |
777 | 777 | | |
778 | | - | |
779 | | - | |
780 | | - | |
781 | | - | |
| 778 | + | |
782 | 779 | | |
783 | 780 | | |
784 | 781 | | |
| |||
807 | 804 | | |
808 | 805 | | |
809 | 806 | | |
810 | | - | |
811 | | - | |
812 | | - | |
813 | | - | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
814 | 812 | | |
815 | 813 | | |
816 | 814 | | |
| |||
851 | 849 | | |
852 | 850 | | |
853 | 851 | | |
854 | | - | |
855 | | - | |
| 852 | + | |
856 | 853 | | |
857 | 854 | | |
858 | 855 | | |
| |||
1090 | 1087 | | |
1091 | 1088 | | |
1092 | 1089 | | |
1093 | | - | |
1094 | | - | |
1095 | | - | |
1096 | | - | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
1097 | 1095 | | |
1098 | 1096 | | |
1099 | 1097 | | |
| |||
1248 | 1246 | | |
1249 | 1247 | | |
1250 | 1248 | | |
1251 | | - | |
1252 | | - | |
1253 | | - | |
1254 | | - | |
| 1249 | + | |
1255 | 1250 | | |
1256 | 1251 | | |
1257 | 1252 | | |
| |||
0 commit comments