diff --git a/common/workunit/wujobq.cpp b/common/workunit/wujobq.cpp index f7b5d9c286d..99c02da2fe7 100644 --- a/common/workunit/wujobq.cpp +++ b/common/workunit/wujobq.cpp @@ -1128,9 +1128,11 @@ class CJobQueue: public CJobQueueBase, implements IJobQueue ForEachQueue(qd) { IPropertyTree *croot = queryClientRootSession(*qd); - unsigned newConnectedCount = croot->getPropInt64("@connected",0)-1; - if (newConnectedCount) - croot->setPropInt64("@connected", newConnectedCount); + unsigned connectedCount = croot->getPropInt64("@connected"); + if (connectedCount) // should never be 0, but guard JIC + connectedCount--; + if (connectedCount) + croot->setPropInt64("@connected", connectedCount); else qd->root->removeTree(croot); }