Commit d6dc64c
committed
Fix NPE in ChannelPool metrics methods when pool is uninitialized
When the initial TCP connection to a node fails, ChannelPool.connectFuture
completes (so the pool is added to PoolManager.pools) while `channels` is
still null — initialize() is only called on the success path.
The four methods size(), getAvailableIds(), getInFlight(), and
getOrphanedIds() called Arrays.stream(channels) without guarding against
this, throwing NullPointerException whenever a Dropwizard Metrics reporter
(JMX, Graphite, etc.) scraped the gauge values during the reconnection
window.
Fix: mirror the pattern already used by next(), which checks
singleThreaded.initialized before touching channels. Using the volatile
initialized flag is correct by the JMM: the volatile write at line 365
(initialized = true) happens-after all channels writes, so any thread
that reads initialized == true is guaranteed to see channels as
fully populated.
Fixes: CUSTOMER-4131 parent 1d65bce commit d6dc64c
1 file changed
Lines changed: 12 additions & 0 deletions
Lines changed: 12 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
210 | 210 | | |
211 | 211 | | |
212 | 212 | | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
213 | 216 | | |
214 | 217 | | |
215 | 218 | | |
216 | 219 | | |
217 | 220 | | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
218 | 224 | | |
219 | 225 | | |
220 | 226 | | |
| |||
223 | 229 | | |
224 | 230 | | |
225 | 231 | | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
226 | 235 | | |
227 | 236 | | |
228 | 237 | | |
| |||
232 | 241 | | |
233 | 242 | | |
234 | 243 | | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
235 | 247 | | |
236 | 248 | | |
237 | 249 | | |
| |||
0 commit comments