Skip to content

Commit

Permalink
Introduce needReport for ResourceLeakDetector. (#9910)
Browse files Browse the repository at this point in the history
Motivation:

We can extend `ResourceLeakDetector` through `ResourceLeakDetectorFactory`, and then report the leaked information by covering `reportTracedLeak` and `reportUntracedLeak`. However, the behavior of `reportTracedLeak` and `reportUntracedLeak` is controlled by `logger.isErrorEnabled()`, which is not reasonable. In the case of extending `ResourceLeakDetector`, we sometimes need `needReport` to always return true instead of relying on `logger.isErrorEnabled ()`.

Modification:

introduce `needReport` method and let it be `protected`

Result:

We can control the report leak behavior.
  • Loading branch information
carryxyh authored and normanmaurer committed Jan 10, 2020
1 parent 76fb4c8 commit b82258b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion common/src/main/java/io/netty/util/ResourceLeakDetector.java
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,18 @@ private void clearRefQueue() {
}
}

/**
* When the return value is {@code true}, {@link #reportTracedLeak} and {@link #reportUntracedLeak}
* will be called once a leak is detected, otherwise not.
*
* @return {@code true} to enable leak reporting.
*/
protected boolean needReport() {
return logger.isErrorEnabled();
}

private void reportLeak() {
if (!logger.isErrorEnabled()) {
if (!needReport()) {
clearRefQueue();
return;
}
Expand Down

0 comments on commit b82258b

Please sign in to comment.