pozil / pub-sub-api-node-client

A node client for the Salesforce Pub/Sub API
Creative Commons Zero v1.0 Universal
72 stars 40 forks source link

Bug in requesting additional events for infinite event request #49

Closed alice-watershed closed 5 days ago

alice-watershed commented 1 week ago

If you open an infinite connection, it only requests 200 events before closing the connection. The sequence of events is:

  1. Open a connection and request 100 events
  2. Receive 100 events
  3. Hit the receivedEventCount === requestedEventCount if statement here
  4. Request 100 additional events. receivedEventCount is not reset to 0 because the code incorrectly sets subscription.receivedEventCount = 0, instead of subscription.info.receivedEventCount = 0
  5. Receive 100 events
  6. At this point, receivedEventCount = 200 and requestedEventCount = 100 so we never hit the if statement again
  7. Close the connection because we received the last event

Incorrect:

requestAdditionalEvents(topicName, numRequested) {
  .........
        // Request additional events
        subscription.receivedEventCount = 0;
        subscription.requestedEventCount = numRequested;
  .........
    }

Correct:

requestAdditionalEvents(topicName, numRequested) {
  .........
        // Request additional events
        subscription.info.receivedEventCount = 0;
        subscription.info.requestedEventCount = numRequested;
  .........
    }
pozil commented 5 days ago

Great catch! Thanks for the detailed description and the source of the error. I fixed it in v5.0.2.