Commit db8d5c5
authored
Fix race in FlowControlHandlerTest that could lead to a NPE (#12457)
Motivation:
How we accessed the internal state of the handler was not thread safe and so we could see a NPE during testing like:
```
2022-06-09T10:27:09.1309221Z java.lang.NullPointerException: Cannot invoke "io.netty5.handler.flow.FlowControlHandler$RecyclableArrayDeque.isEmpty()" because "this.queue" is null
2022-06-09T10:27:09.1310056Z at io.netty5.handler.flow.FlowControlHandler.isQueueEmpty(FlowControlHandler.java:90)
2022-06-09T10:27:09.1310829Z at io.netty5.handler.flow.FlowControlHandlerTest.testFlowAutoReadOff(FlowControlHandlerTest.java:370)
2022-06-09T10:27:09.1311575Z at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2022-06-09T10:27:09.1312301Z at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
2022-06-09T10:27:09.1313093Z at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2022-06-09T10:27:09.1313760Z at java.base/java.lang.reflect.Method.invoke(Method.java:568)
2022-06-09T10:27:09.1314400Z at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:725)
2022-06-09T10:27:09.1315137Z at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
2022-06-09T10:27:09.1315983Z at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
2022-06-09T10:27:09.1316828Z at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:149)
2022-06-09T10:27:09.1317641Z at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:140)
2022-06-09T10:27:09.1318493Z at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:84)
2022-06-09T10:27:09.1319348Z at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)
2022-06-09T10:27:09.1320165Z at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
2022-06-09T10:27:09.1321012Z at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
2022-06-09T10:27:09.1322136Z at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
2022-06-09T10:27:09.1323045Z at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
2022-06-09T10:27:09.1323943Z at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
2022-06-09T10:27:09.1324743Z at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)
2022-06-09T10:27:09.1325482Z at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)
2022-06-09T10:27:09.1326315Z at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:214)
2022-06-09T10:27:09.1327204Z at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
2022-06-09T10:27:09.1328123Z at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:210)
2022-06-09T10:27:09.1329864Z at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:135)
2022-06-09T10:27:09.1330733Z at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:66)
2022-06-09T10:27:09.1331591Z at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151)
2022-06-09T10:27:09.1332454Z at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
2022-06-09T10:27:09.1333319Z at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
2022-06-09T10:27:09.1334081Z at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
2022-06-09T10:27:09.1334851Z at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
2022-06-09T10:27:09.1335715Z at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
2022-06-09T10:27:09.1336583Z at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
2022-06-09T10:27:09.1337418Z at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
2022-06-09T10:27:09.1338067Z at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
2022-06-09T10:27:09.1338985Z at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
2022-06-09T10:27:09.1340052Z at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
2022-06-09T10:27:09.1340908Z at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
2022-06-09T10:27:09.1341965Z at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
2022-06-09T10:27:09.1342739Z at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
2022-06-09T10:27:09.1343508Z at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
2022-06-09T10:27:09.1344444Z at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
2022-06-09T10:27:09.1345330Z at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
2022-06-09T10:27:09.1346176Z at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
2022-06-09T10:27:09.1346868Z at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
2022-06-09T10:27:09.1347789Z at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
2022-06-09T10:27:09.1348854Z at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
2022-06-09T10:27:09.1349822Z at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
2022-06-09T10:27:09.1350695Z at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
2022-06-09T10:27:09.1351529Z at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
2022-06-09T10:27:09.1352298Z at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
2022-06-09T10:27:09.1353161Z at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
2022-06-09T10:27:09.1354049Z at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
2022-06-09T10:27:09.1354894Z at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
2022-06-09T10:27:09.1355997Z at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
2022-06-09T10:27:09.1357115Z at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
2022-06-09T10:27:09.1358070Z at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
2022-06-09T10:27:09.1358898Z at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:220)
2022-06-09T10:27:09.1359628Z at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:188)
2022-06-09T10:27:09.1360424Z at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:202)
2022-06-09T10:27:09.1361216Z at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:181)
2022-06-09T10:27:09.1361937Z at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128)
2022-06-09T10:27:09.1362790Z at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invokeAllTests(JUnitPlatformProvider.java:150)
2022-06-09T10:27:09.1363688Z at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invoke(JUnitPlatformProvider.java:124)
2022-06-09T10:27:09.1364571Z at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:384)
2022-06-09T10:27:09.1365399Z at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:345)
2022-06-09T10:27:09.1366134Z at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:126)
2022-06-09T10:27:09.1366804Z at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:418)
2022-06-09T10:27:09.1375974Z
```
Modifications:
Dispatch the EventLoop before accessing the state
Result:
No more NPE possible1 parent bc085b0 commit db8d5c5
1 file changed
Lines changed: 58 additions & 10 deletions
Lines changed: 58 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
| |||
215 | 216 | | |
216 | 217 | | |
217 | 218 | | |
| 219 | + | |
218 | 220 | | |
219 | 221 | | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
220 | 229 | | |
221 | 230 | | |
| 231 | + | |
222 | 232 | | |
223 | 233 | | |
224 | 234 | | |
225 | 235 | | |
226 | | - | |
| 236 | + | |
227 | 237 | | |
228 | 238 | | |
229 | 239 | | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
230 | 243 | | |
231 | 244 | | |
232 | 245 | | |
233 | 246 | | |
234 | 247 | | |
235 | 248 | | |
236 | | - | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
237 | 256 | | |
238 | 257 | | |
239 | 258 | | |
| |||
292 | 311 | | |
293 | 312 | | |
294 | 313 | | |
295 | | - | |
| 314 | + | |
296 | 315 | | |
297 | 316 | | |
298 | 317 | | |
| |||
314 | 333 | | |
315 | 334 | | |
316 | 335 | | |
317 | | - | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
318 | 343 | | |
319 | 344 | | |
320 | 345 | | |
| |||
348 | 373 | | |
349 | 374 | | |
350 | 375 | | |
351 | | - | |
| 376 | + | |
352 | 377 | | |
353 | 378 | | |
354 | 379 | | |
| |||
370 | 395 | | |
371 | 396 | | |
372 | 397 | | |
373 | | - | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
374 | 405 | | |
375 | 406 | | |
376 | 407 | | |
| |||
401 | 432 | | |
402 | 433 | | |
403 | 434 | | |
404 | | - | |
| 435 | + | |
405 | 436 | | |
406 | 437 | | |
407 | 438 | | |
| |||
415 | 446 | | |
416 | 447 | | |
417 | 448 | | |
418 | | - | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
419 | 456 | | |
420 | 457 | | |
421 | 458 | | |
| |||
485 | 522 | | |
486 | 523 | | |
487 | 524 | | |
| 525 | + | |
| 526 | + | |
488 | 527 | | |
489 | 528 | | |
490 | 529 | | |
491 | 530 | | |
492 | 531 | | |
| 532 | + | |
493 | 533 | | |
494 | 534 | | |
495 | 535 | | |
| |||
501 | 541 | | |
502 | 542 | | |
503 | 543 | | |
504 | | - | |
| 544 | + | |
505 | 545 | | |
506 | 546 | | |
507 | 547 | | |
| |||
530 | 570 | | |
531 | 571 | | |
532 | 572 | | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
533 | 576 | | |
534 | 577 | | |
535 | 578 | | |
536 | 579 | | |
537 | 580 | | |
538 | | - | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
539 | 587 | | |
540 | 588 | | |
541 | 589 | | |
| |||
0 commit comments