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] processError() is stuck if subscription is closed in it #9289

Closed
ramya-rao-a opened this issue Jun 4, 2020 · 1 comment · Fixed by #9491
Closed

[Event Hubs] processError() is stuck if subscription is closed in it #9289

ramya-rao-a opened this issue Jun 4, 2020 · 1 comment · Fixed by #9491
Assignees
Labels
Client This issue points to a problem in the data-plane of the library. Event Hubs
Milestone

Comments

@ramya-rao-a
Copy link
Contributor

Run the below code with a connection string to a valid namespace, but pass an invalid eventHubName so that processError is called

const { EventHubConsumerClient } = require("@azure/event-hubs");

async function main() {

  const client = new EventHubConsumerClient("$Default", connectionString, eventHubName);

  let subscription;
  const caughtErr = await new Promise((resolve) => {
    subscription = client.subscribe({
      processEvents: async () => {},
      processError: async (err) => {
        await subscription.close();
        console.log("Subscription closed")
        resolve(err);
      }
    });
  });

  console.log("Caught error", caughtErr);
  
  await client.close();
  console.log("Client closed")

}
main();

The program exits after a minute or so, but no code after await subscription.close() gets called.

cc @richardpark-msft, @chradek

@ghost ghost added the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Jun 4, 2020
@ramya-rao-a ramya-rao-a added Client This issue points to a problem in the data-plane of the library. Event Hubs labels Jun 4, 2020
@ghost ghost removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Jun 4, 2020
@ramya-rao-a ramya-rao-a modified the milestones: Backlog, [2020] July Jun 4, 2020
@chradek chradek self-assigned this Jun 11, 2020
@chradek
Copy link
Contributor

chradek commented Jun 11, 2020

This behavior is being caused because we have some circular awaits in this scenario. Here's what's happening:

  1. EventProcessor loop begins.
  2. Call to get partition ids fail due to bad eventHubName, enter catch block in loop.
  3. Inside catch block, we await processError.
  4. User's processError awaits subscription.close().
  5. subscription.close() waits for the EventProcessor loop to exit before yielding.

It's at this point that we've reached a holding pattern, since processError won't yield to the loop until the loop has closed...which it can't do until processError yields!

As for why the process still exits...I'm not sure. It seems like the runtime can tell that these promises are deadlocked, but that's a separate deep dive.

Additional note: This happens when processError is invoked for a non partition-specific issue. These would be things unrelated to processing events such as getting the list of partition claims and partition ids.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Client This issue points to a problem in the data-plane of the library. Event Hubs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants