Skip to content

Commit

Permalink
Fixed leak of inotify instances.
Browse files Browse the repository at this point in the history
  • Loading branch information
AnatolyPopov committed Nov 2, 2021
1 parent 69c9e48 commit 56a2e43
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/main/java/io/aiven/kafka/auth/AivenAclAuthorizerV2.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,13 @@ public class AivenAclAuthorizerV2 implements Authorizer {
private File configFile;
private AuditorAPI auditor;
private boolean logDenials;
private final ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
private final WatchService watchService;
private ScheduledExecutorService scheduledExecutorService;
private WatchService watchService;
private final AtomicReference<VerdictCache> cacheReference = new AtomicReference<>();

private AivenAclAuthorizerConfig config;

public AivenAclAuthorizerV2() {
try {
watchService = FileSystems.getDefault().newWatchService();
} catch (final IOException e) {
LOGGER.error("Failed to initialize WatchService", e);
throw new RuntimeException(e);
}
}

@Override
Expand All @@ -93,6 +87,8 @@ public void configure(final java.util.Map<String, ?> configs) {
final AuthorizerServerInfo serverInfo) {
auditor = config.getAuditor();
logDenials = config.logDenials();
watchService = initializeWatchService();
scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();

configFile = config.getConfigFile();
final AclJsonReader jsonReader = new AclJsonReader(configFile.toPath());
Expand Down Expand Up @@ -128,6 +124,15 @@ public void configure(final java.util.Map<String, ?> configs) {
));
}

private WatchService initializeWatchService() {
try {
return FileSystems.getDefault().newWatchService();
} catch (final IOException e) {
LOGGER.error("Failed to initialize WatchService", e);
throw new RuntimeException(e);
}
}

private WatchKey subscribeToAclChanges(final File configFile) {
try {
return configFile.toPath().toAbsolutePath().getParent()
Expand Down

0 comments on commit 56a2e43

Please sign in to comment.