Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[event-hubs] fixes sendBatch race condition causing TypeError to be thrown #15021

Merged
merged 5 commits into from
Apr 26, 2021

Conversation

chradek
Copy link
Contributor

@chradek chradek commented Apr 26, 2021

Fixes #15002

Background

@azure/event-hubs 5.5.0 introduced a bug where a TypeError could be thrown from EventHubProducerClient.sendBatch if the connection was disconnected between the points where the sender link was initialized and the events were sent to the service.

This was because the logic to initialize the sender link and the logic to actually send events across the link were separated into separate retriable operations. When a connection disconnected event is encountered after the link is initialized, the existing link is closed. However, the sending of events can be retried. Since the link was closed, we'd get our version of a null pointer error when trying to interact with the link.

Changes

This PR does 2 things to fix the issue and prevent future 'null pointer' exceptions.

  1. We recombine the link initialization and sending of events into the same retriable operation. This way, if the disconnected event occurs and the link has been closed, we'll recreate the link before trying to send the events again.
  2. The EventHubSender._trySendBatch method has been updated to remove all of our TypeScript non-null assertions. ) _createLinkIfNotOpen` has been updated to return the sender link that's created directly so we can be sure it exists before we try to use it.

What about Service Bus?

I looked at the Service Bus code and it already keeps the link initialization and sending of events in the same retriable operation. It currently does use a non-null type assertion on the sender link, though because the link initialization and sending of events are currently combined, this should be safe for now.

@chradek
Copy link
Contributor Author

chradek commented Apr 26, 2021

/azp run js - event-hubs - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@chradek
Copy link
Contributor Author

chradek commented Apr 26, 2021

/azp run js - event-hubs - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@chradek
Copy link
Contributor Author

chradek commented Apr 26, 2021

/azp run js - event-hubs - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@chradek chradek merged commit b3db04d into Azure:master Apr 26, 2021
@chradek chradek deleted the eh-fix-sender-typeerror branch April 26, 2021 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[event-hubs] EventHubProducerClient.sendBatch can throw TypeError "Cannot read property 'credit' of undefined"
2 participants