google / log4jscanner

A log4j vulnerability filesystem scanner and Go package for analyzing JAR files.
Apache License 2.0
1.56k stars 121 forks source link

jar: fix pool.Dynamic test flakiness #58

Closed aktau closed 2 years ago

aktau commented 2 years ago

The test flakiness is due to the sync.Pool sometimes forgetting values, when there is GC pressure. This is part of the stated behaviour of a pool, I just though this single test would always respond the same way given the same GOGC. That was, of course, overly optimistic. It shows me I shouldn't rely on a sync.Pool behaving "simply" even for single goroutine cases. There's two options:

  1. Only rely on the return value of Put() for tests (though this would weaken the test a bit).
  2. Use a simpler pool for tests, which doesn't forget values.

I've chosen option #2.