Fix threads leak when PostTask is executed
Issue:
When PostTask is created it receives executor that is created by
ExecutorProvider. Provider is not scoped therefore new instance is
created each time when new PostTask is created. As a result executors
are being constantly created and never re-used.
Solution:
Bind ExecutorProvider to SINGLETON scope so that it keeps returning the
same executor that is effectively re-used by PostTask instances.
Note: to increase throughput default threadPoolSize was increased to 2.
Change-Id: I6ae0a2cf9f17df529a209735eca30593891194c3
Signed-off-by: Jacek Centkowski <jcentkowski@collab.net>
diff --git a/src/main/java/com/googlesource/gerrit/plugins/webhooks/Configuration.java b/src/main/java/com/googlesource/gerrit/plugins/webhooks/Configuration.java
index 5dda6b4..416b6ee 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/webhooks/Configuration.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/webhooks/Configuration.java
@@ -29,7 +29,7 @@
private static final int DEFAULT_TIMEOUT_MS = 5000;
private static final int DEFAULT_MAX_TRIES = 5;
private static final int DEFAULT_RETRY_INTERVAL = 1000;
- private static final int DEFAULT_THREAD_POOL_SIZE = 1;
+ private static final int DEFAULT_THREAD_POOL_SIZE = 2;
private final int connectionTimeout;
private final int socketTimeout;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/webhooks/Module.java b/src/main/java/com/googlesource/gerrit/plugins/webhooks/Module.java
index 3c7a5db..00a6bfb 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/webhooks/Module.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/webhooks/Module.java
@@ -34,7 +34,8 @@
protected void configure() {
bind(ScheduledExecutorService.class)
.annotatedWith(WebHooksExecutor.class)
- .toProvider(ExecutorProvider.class);
+ .toProvider(ExecutorProvider.class)
+ .in(Scopes.SINGLETON);
bind(CloseableHttpClient.class).toProvider(HttpClientProvider.class).in(Scopes.SINGLETON);
factory(PostTask.Factory.class);
factory(RemoteConfig.Factory.class);
diff --git a/src/main/resources/Documentation/config.md b/src/main/resources/Documentation/config.md
index 338a289..88ecdba 100644
--- a/src/main/resources/Documentation/config.md
+++ b/src/main/resources/Documentation/config.md
@@ -66,4 +66,4 @@
@PLUGIN@.threadPoolSize
: Maximum number of threads used to send events to the target instance.
- Defaults to 1.
+ Defaults to 2.
\ No newline at end of file