Skip to content

Commit

Permalink
Merge pull request #43 from aiven/anatolii/inotify-leak-fix
Browse files Browse the repository at this point in the history
Fixed leak of inotify instances
  • Loading branch information
ivanyu authored Nov 3, 2021
2 parents 69c9e48 + ae0f379 commit 4b784ce
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 volatile 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 4b784ce

Please sign in to comment.