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

ISSUE-119: Unhandled Promise Rejection On Failed createProducer #74

Closed
sijie opened this issue Sep 11, 2020 · 0 comments
Closed

ISSUE-119: Unhandled Promise Rejection On Failed createProducer #74

sijie opened this issue Sep 11, 2020 · 0 comments

Comments

@sijie
Copy link
Member

sijie commented Sep 11, 2020

Original Issue: apache#119


When creating a producer using a client URL that is intentionally incorrect via the following:

const client = new Pulsar.Client({
	serviceUrl: 'pulsar://this-will-fail:6650',
	ioThreads: 6
})
client.createProducer({
	topic: 'persistent://test/a/b',
}).then((producer) => {
	// ...
}).catch((err) => {
	// ...
})

I get the following unhandled promise rejection warning:

[ClientConnection:469] [<none> -> pulsar://this-will-fail:6650] Resolve error: asio.netdb:1 : Host not found (authoritative)
(node:15) UnhandledPromiseRejectionWarning: Error: Failed to create producer: ConnectError
(node:15) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:15) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Upon further inspection of the code the error originates from the following line:
https://github.com/apache/pulsar-client-node/blob/eaba0dcd9b8e04fe7c23feb0c0ec6e424a817f64/src/Consumer.cc#L134

Where ConsumerNewInstanceWorker is a Napi::AsyncWorker:
https://github.com/apache/pulsar-client-node/blob/eaba0dcd9b8e04fe7c23feb0c0ec6e424a817f64/src/Consumer.cc#L94-L102

I did some quick checking into using Promises with AsyncWorker and there is a proposed solution mentioned here on the NAPI repository: nodejs/node-addon-api#231 (comment)

I'd be willing to incorporate this solution and create a pull request, if it would be welcome, but I wanted to discuss it here first before making any changes.

I'd also be willing to help out with some of the other requests here, as well.
I'll be using this in production going forward.

@sijie sijie closed this as completed Sep 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant