Sitelet https://github.com/ethereum-optimism/optimism/commit/1214693add3b0aa5ce535df197b5b1f710d8a49e
Skip to content

Commit 1214693

Browse files
ajsuttonclaude
andauthored
fix(op-batcher): fix flaky TestChannelManager_Memory (#19579)
* fix(op-batcher): fix flaky TestChannelManager_Memory by using TotalAlloc The test measured memory using `runtime.MemStats.Alloc` (current heap size), which can decrease after GC runs. The subtraction `finalMem.Alloc - initialMem.Alloc` on uint64 values underflows when GC reclaims enough memory between the two reads, producing a massive number that exceeds the 512MB threshold. Switch to `TotalAlloc` which is monotonically increasing and safe to subtract. Raise the threshold to 1GB since TotalAlloc counts cumulative allocations including freed memory. Actual usage is ~30MB, so the threshold provides ample headroom. Flake count: 19 in CircleCI (go-tests-short). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix(op-batcher): use HeapInuse absolute threshold for TestChannelManager_Memory Address review feedback: use HeapInuse after GC as absolute threshold instead of TotalAlloc delta. This correctly measures retained memory (catching leaks) while eliminating the uint64 underflow that caused flakiness. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix(op-batcher): guard against uint64 underflow in TestChannelManager_Memory The test measures retained memory by subtracting initial Alloc from final Alloc. When GC reclaims memory between the two ReadMemStats calls (from other goroutines), final Alloc can be less than initial Alloc, causing a uint64 underflow that produces a massive value and fails the 512MB check. Guard the subtraction: if final < initial, treat the delta as zero. This preserves the original test semantics (bounding retained heap) while handling the GC timing edge case that causes intermittent failures. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 3732655 commit 1214693

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

‎op-batcher/batcher/channel_manager_memory_test.go‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,14 @@ func runMemoryTest(t *testing.T, batchType uint, compressorType string, compress
141141
runtime.GC()
142142
runtime.ReadMemStats(&finalMem)
143143

144-
// Calculate memory used by the channel manager
145-
memUsed := finalMem.Alloc - initialMem.Alloc
144+
// Calculate memory used by the channel manager.
145+
// Guard against uint64 underflow: GC between the two ReadMemStats calls can
146+
// reclaim memory from other goroutines, making finalMem.Alloc < initialMem.Alloc.
147+
// When that happens the delta is effectively zero — no leak detected.
148+
var memUsed uint64
149+
if finalMem.Alloc > initialMem.Alloc {
150+
memUsed = finalMem.Alloc - initialMem.Alloc
151+
}
146152

147153
// Assert that memory usage doesn't exceed 512MB
148154
const maxMemoryMB = 512 * 1024 * 1024 // 512MB in bytes

0 commit comments

Comments
 (0)