Skip to content

Commit b2aa707

Browse files
Merge pull request #88 from kaleido-io/one-ack-per-batch
Only send one ack per batch
2 parents f5e90e5 + 935b19f commit b2aa707

2 files changed

Lines changed: 18 additions & 9 deletions

File tree

Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ RUN mkdir -p /home/node/contracts/source
2121
RUN chown node:node /home/node/contracts/source
2222
WORKDIR /home/node/contracts/source
2323
USER node
24-
COPY --from=solidity-build /home/node/contracts /home/node/package*.json ./
24+
COPY --from=solidity-build --chown=node:node /home/node/contracts /home/node/package*.json ./
2525
RUN npm install --production
2626
WORKDIR /home/node/contracts
27-
COPY --from=solidity-build /home/node/artifacts/contracts/TokenFactory.sol/TokenFactory.json ./
27+
COPY --from=solidity-build --chown=node:node /home/node/artifacts/contracts/TokenFactory.sol/TokenFactory.json ./
2828
WORKDIR /home/node
29-
COPY --from=build /home/node/dist ./dist
30-
COPY --from=build /home/node/package.json /home/node/package-lock.json ./
29+
COPY --from=build --chown=node:node /home/node/dist ./dist
30+
COPY --from=build --chown=node:node /home/node/package.json /home/node/package-lock.json ./
3131

3232

3333
RUN npm install --production

src/eventstream-proxy/eventstream-proxy.base.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,21 @@ export abstract class EventStreamProxyBase extends WebSocketEventsBase {
190190
return;
191191
}
192192

193-
this.logger.log(`Received ack ${data.id}`);
194-
if (this.socket !== undefined && this.awaitingAck.find(msg => msg.id === data.id)) {
195-
const firstAck = this.awaitingAck.find(msg => msg.id === data.id);
193+
const inflight = this.awaitingAck.find(msg => msg.id === data.id)
194+
this.logger.log(`Received ack ${data.id} inflight=${!!inflight}`);
195+
if (this.socket !== undefined && inflight !== undefined) {
196196
this.awaitingAck = this.awaitingAck.filter(msg => msg.id !== data.id);
197-
if (firstAck) {
198-
this.socket.ack(firstAck.batchNumber);
197+
if (
198+
// If nothing is left awaiting an ack - then we clearly need to ack
199+
this.awaitingAck.length === 0 ||
200+
(
201+
// Or if we have a batch number associated with this ID, then we can only ack if there
202+
// are no other messages in-flight with the same batch number.
203+
inflight.batchNumber !== undefined && !this.awaitingAck.find(msg => msg.batchNumber === inflight.batchNumber)
204+
)
205+
) {
206+
this.logger.log(`In-flight batch complete (batchNumber=${inflight.batchNumber})`);
207+
this.socket.ack(inflight.batchNumber);
199208
}
200209
}
201210
}

0 commit comments

Comments
 (0)