question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sample code produces TypeError: Cannot read property 'sequenceNumber' of undefined' when eventhub is empty

See original GitHub issue
  • Package Name: azure/event-hubs
  • Package Version: 5.2.2
  • Operating system: Linux
  • nodejs
    • version: v13.8.0
  • Is the bug related to documentation in

Describe the bug When running the SDK sample code for reading events (reproduced below with the timeout promise removed) from an eventhub I successfully get events BUT I also receive errors when the eventhub has nothing on it. These being ‘TypeError: Cannot read property ‘sequenceNumber’ of undefined’. I’m guessing that somewhere in the library some garbage is being ‘taken’ off the queue and interpreted as a message causing an error.

To Reproduce Steps to reproduce the behavior:

  1. Set up a new event hub
  2. Run code and wait a while
const { EventHubConsumerClient } = require("@azure/event-hubs");
const { ContainerClient } = require("@azure/storage-blob");
const { BlobCheckpointStore } = require("@azure/eventhubs-checkpointstore-blob");

const connectionString = process.env.EHCONNECTIONSTRING;
const eventHubName = process.env.EHNAME;
const consumerGroup = "$Default"; // name of the default consumer group
const storageConnectionString = process.env.AZURE_STORAGE_CONNECTION_STRING;
const containerName = process.env.EHCONTAINER;

async function main() {
  // Create a blob container client and a blob checkpoint store using the client.
  const containerClient = new ContainerClient(storageConnectionString, containerName);
  const checkpointStore = new BlobCheckpointStore(containerClient);

  // Create a consumer client for the event hub by specifying the checkpoint store.
  const consumerClient = new EventHubConsumerClient(consumerGroup, connectionString, eventHubName, checkpointStore);

  // Subscribe to the events, and specify handlers for processing the events and errors.
  const subscription = consumerClient.subscribe({
      processEvents: async (events, context) => {
        for (const event of events) {
          console.log(`Received event: '${event.body}' from partition: '${context.partitionId}' and consumer group: '${context.consumerGroup}'`);
        }
        // Update the checkpoint.
        await context.updateCheckpoint(events[events.length - 1]);
      },

      processError: async (err, context) => {
        console.log(`Error : ${err}`);
      }
    }
  );
}

main().catch((err) => {
  console.log("Error occurred: ", err);
});

Expected behavior No errors produced

Screenshots If applicable, add screenshots to help explain your problem. image

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
nVitiuscommented, Oct 14, 2020

The docs on the Microsoft website still show up with the outdated version of this code: https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-node-get-started-send

1reaction
richardpark-msftcommented, Sep 3, 2020

@ramya-rao-a , @robeving - looks like this is a simple one. EventHubs will return zero events if the wait time expires with no messages arriving (as you’re seeing).

This is useful if you just want an indicator that receiving is still active but it means that this line in our sample is bad when events is empty.

  await context.updateCheckpoint(events[events.length - 1]);

I’ll update the samples. The simplest fix is just to check that events.length === 0 so your processEvents method is similar to this:

   processEvents: async (events, context) => {
       if (events.length === 0) {
          console.log(`No events received within wait time. Waiting for next interval`);
          return;
        }

        for (const event of events) {
          console.log(`Received event: '${event.body}' from partition: '${context.partitionId}' and consumer group: '${context.consumerGroup}'`);
        }
        // Update the checkpoint.
        await context.updateCheckpoint(events[events.length - 1]);
      },

We have this concept in a few spots so I’ll need to validate them all:

  • EventHubs checkpoint store samples
  • EventHubs checkpoint store readme
  • EventHubs readme
Read more comments on GitHub >

github_iconTop Results From Across the Web

Azure Eventhub Sequence Number sequencing
Thus, SequenceNumber presented by client (read from checkpoint store) was greater than latest sequence number at service.
Read more >
EventData.SequenceNumber Property (Azure.Messaging ...
This value is read-only and will only be populated for events that have been read from Event Hubs. The default value when not...
Read more >
azure-eventhub - PyPI
This lets you process and analyze the massive amounts of data produced by your connected devices and applications. Once Event Hubs has collected...
Read more >
Errors COnnecting to Azure Event hub - Forums - IBM Support
Hello All,. I'm getting the following error while setting up a log source for Azure Event hubs . My internal Azure team has...
Read more >
Azure Event Hubs Source Connector for Confluent Cloud
PartitionKey property is null and when the x-opt-kafka-key is present. "azure.eventhubs.transport.type" : (Optional) Sets the transport type for communicating ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found