Skip to content

Commit

Permalink
Handle unexpected exceptions in SystemResourceMonitors.
Browse files Browse the repository at this point in the history
Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
  • Loading branch information
boaks committed May 2, 2024
1 parent b47776d commit 1aae0e4
Showing 1 changed file with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,16 @@ private synchronized void start() {
*/
private void checkNow() {
if (pending.compareAndSet(false, true)) {
ScheduledFuture<?> future = scheduled.get();
if (future != null) {
future.cancel(false);
try {
ScheduledFuture<?> future = scheduled.get();
if (future != null) {
future.cancel(false);
}
resource.checkForUpdate(this);
} catch (RuntimeException ex) {
LOGGER.info("{} unexpected error!", name, ex);
ready(false);
}
resource.checkForUpdate(this);
}
}

Expand All @@ -296,8 +301,13 @@ private void checkNow() {
*/
private void check() {
if (pending.compareAndSet(false, true)) {
LOGGER.info("{} check for update!", name);
resource.checkForUpdate(this);
try {
LOGGER.info("{} check for update!", name);
resource.checkForUpdate(this);
} catch (RuntimeException ex) {
LOGGER.info("{} unexpected error!", name, ex);
ready(false);
}
} else {
LOGGER.info("{} check for update pending!", name);
}
Expand Down Expand Up @@ -418,8 +428,13 @@ private MonitoredValues readMonitoredValues() {
public void checkForUpdate(SystemResourceCheckReady ready) {
MonitoredValues values = readMonitoredValues();
if (this.values.check(values)) {
LOGGER.info("File {} changed!", file);
update(values, ready);
try {
LOGGER.info("File {} changed!", file);
update(values, ready);
} catch (RuntimeException ex) {
ready(values);
throw ex;
}
} else {
LOGGER.info("File {} unchanged.", file);
ready.ready(false);
Expand Down

0 comments on commit 1aae0e4

Please # to comment.