Skip to content

Commit

Permalink
7.5.2
Browse files Browse the repository at this point in the history
- FIX: 100% cpu usage due to: user limit of inotify instances reached
  • Loading branch information
Osiris-Team committed Dec 22, 2023
1 parent 3b0049a commit 0b8e8bc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<groupId>com.osiris.autoplug.client</groupId>
<artifactId>autoplug-client</artifactId>
<version>7.5.1</version>
<version>7.5.2</version>
<packaging>jar</packaging>

<name>AutoPlug-Client</name>
Expand Down
41 changes: 29 additions & 12 deletions src/main/java/com/osiris/autoplug/client/configs/MyYaml.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public MyYaml(String filePath, boolean isPostProcessingEnabled, boolean isDebugE
/**
* Pairs of absolute file path and count of pending programmatic save events for that file.
*/
private static final Map<String, Integer> filesAndPEvents = new HashMap<>();
private static final Map<String, PSave> filesAndPEvents = new HashMap<>();

private long msLastEvent = 0;

Expand All @@ -95,9 +95,8 @@ public Yaml addSingletonConfigFileEventListener(Consumer<FileEvent> listener) th
String path = file.getAbsolutePath();

synchronized (filesAndPEvents) {
if (!filesAndPEvents.containsKey(path)) {
filesAndPEvents.put(path, 0);
}
if (filesAndPEvents.containsKey(path)) return this; // Already exists
filesAndPEvents.put(path, new PSave());
}

super.addFileEventListener(e -> {
Expand All @@ -106,11 +105,12 @@ public Yaml addSingletonConfigFileEventListener(Consumer<FileEvent> listener) th
AL.info(preInfo + "Deleted. Thus clean config with defaults will be created once ist needed.");
if (e.isModifyEvent()) {
synchronized (filesAndPEvents) {
int pendingProgrammaticSaveEvents = filesAndPEvents.get(path);
if (pendingProgrammaticSaveEvents != 0) {
pendingProgrammaticSaveEvents--;
if (pendingProgrammaticSaveEvents >= 0) // Prevent negative values
filesAndPEvents.put(path, pendingProgrammaticSaveEvents);
PSave p = filesAndPEvents.get(path);
//AL.info(preInfo+" pending: "+p.pendingSaveCount);
if (p.pendingSaveCount != 0) {
p.pendingSaveCount--;
if (p.pendingSaveCount < 0) // Prevent negative values
p.pendingSaveCount = 0;
// Prevent stackoverflow from recursive programmatic save events.
// Only allow user save events.
return;
Expand Down Expand Up @@ -157,11 +157,28 @@ public Yaml addSingletonConfigFileEventListener(Consumer<FileEvent> listener) th
public Yaml save(boolean overwrite) throws IOException, DuplicateKeyException, YamlReaderException, IllegalListException, YamlWriterException {
validateValues();
synchronized (filesAndPEvents) {
String p = file.getAbsolutePath();
if (filesAndPEvents.containsKey(p)) {
filesAndPEvents.put(p, filesAndPEvents.get(p) + 1);
String path = file.getAbsolutePath();
if (filesAndPEvents.containsKey(path)) {
PSave p = filesAndPEvents.get(path);
// If save events are to close after each other the listener fails to differentiate them
// and only notices one event, thus to prevent incrementing the count by adding a delay between saves
long msCurrentSave = System.currentTimeMillis();
//AL.info(""+ (msCurrentSave - p.msLastSave));
if (msCurrentSave - p.msLastSave >= 50) {
//AL.info("save() "+this.file.getName()+" filesAndPEvents.get(p) + 1 = "+ (p.pendingSaveCount + 1));
p.pendingSaveCount++;
}
p.msLastSave = msCurrentSave;
}
}
return super.save(overwrite);
}

/**
* Programmatic save of a yaml file.
*/
public static class PSave {
public long msLastSave = System.currentTimeMillis();
public int pendingSaveCount = 0;
}
}

0 comments on commit 0b8e8bc

Please sign in to comment.