Fix race condition for bolus cancel

This commit is contained in:
TebbeUbben 2019-02-02 11:41:16 +01:00
parent a282124497
commit 71c4c411b2

View file

@ -152,6 +152,8 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
} }
}; };
private final Object $bolusLock = new Object[0];
private boolean bolusInProgress;
private int bolusID = -1; private int bolusID = -1;
private List<BasalProfileBlock> profileBlocks; private List<BasalProfileBlock> profileBlocks;
private boolean limitsFetched; private boolean limitsFetched;
@ -498,12 +500,14 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();
if (detailedBolusInfo.insulin > 0) { if (detailedBolusInfo.insulin > 0) {
try { try {
DeliverBolusMessage bolusMessage = new DeliverBolusMessage(); synchronized ($bolusLock) {
bolusMessage.setBolusType(BolusType.STANDARD); DeliverBolusMessage bolusMessage = new DeliverBolusMessage();
bolusMessage.setDuration(0); bolusMessage.setBolusType(BolusType.STANDARD);
bolusMessage.setExtendedAmount(0); bolusMessage.setDuration(0);
bolusMessage.setImmediateAmount(detailedBolusInfo.insulin); bolusMessage.setExtendedAmount(0);
bolusID = connectionService.requestMessage(bolusMessage).await().getBolusId(); bolusMessage.setImmediateAmount(detailedBolusInfo.insulin);
bolusID = connectionService.requestMessage(bolusMessage).await().getBolusId();
}
result.success = true; result.success = true;
result.enacted = true; result.enacted = true;
Treatment t = new Treatment(); Treatment t = new Treatment();
@ -562,16 +566,18 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
@Override @Override
public void stopBolusDelivering() { public void stopBolusDelivering() {
new Thread(() -> { new Thread(() -> {
try { synchronized ($bolusLock) {
alertService.ignore(AlertType.WARNING_38); try {
CancelBolusMessage cancelBolusMessage = new CancelBolusMessage(); alertService.ignore(AlertType.WARNING_38);
cancelBolusMessage.setBolusID(bolusID); CancelBolusMessage cancelBolusMessage = new CancelBolusMessage();
connectionService.requestMessage(cancelBolusMessage).await(); cancelBolusMessage.setBolusID(bolusID);
confirmAlert(AlertType.WARNING_38); connectionService.requestMessage(cancelBolusMessage).await();
} catch (InsightException e) { confirmAlert(AlertType.WARNING_38);
log.info("Exception while canceling bolus: " + e.getClass().getCanonicalName()); } catch (InsightException e) {
} catch (Exception e) { log.info("Exception while canceling bolus: " + e.getClass().getCanonicalName());
log.error("Exception while canceling bolus", e); } catch (Exception e) {
log.error("Exception while canceling bolus", e);
}
} }
}).start(); }).start();
} }