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.

Uncatchable exception thrown in MqttClientConnection.connect()

See original GitHub issue

Known Issue

  • I’m using ATS data type endpoint: the endpoint should look like <prefix>-ats.iot.<region>.amazonaws.com

Describe the bug If connect() fails an uncatchable exception is thrown.

I am using JITP for our devices, but when connecting using the AWS IoT SDK v2 for JavaScript, and the device gets disconnected after the first connect (which IS expected), the disconnect creates an uncatchable exception.

SDK version number 1.8.3

Platform/OS/Hardware/Device node.js v16.5.0

To Reproduce (observed behavior)

import { mqtt, io, iot } from 'aws-iot-device-sdk-v2'

io.enable_logging(io.LogLevel.DEBUG)
const clientBootstrap = new io.ClientBootstrap()

const mqttEndpoint = 'foo-ats.iot.eu-west-1.amazonaws.com'
const clientId = 'bar'
const cfg = iot.AwsIotMqttConnectionConfigBuilder.new_mtls_builder('foo', 'bar')
cfg.with_clean_session(true)
cfg.with_client_id(clientId)
cfg.with_endpoint(mqttEndpoint)
;(async () => {
	const client = new mqtt.MqttClient(clientBootstrap)
	const connection = client.new_connection(cfg.build())
	try {
		await connection.connect()
	} catch (err) {
		console.error('Caught', err)
	}
})()

Expected behavior It should be possible to handle this exception using try/catch

Logs/output

[INFO] [2021-07-20T15:09:41Z] [00007f42d3eae780] [dns] - id=0x562cd24d78f0: Initializing default host resolver with 64 max host entries.
[INFO] [2021-07-20T15:09:41Z] [00007f42d3eae780] [channel-bootstrap] - id=0x562cd219f4c0: Initializing client bootstrap with event-loop group 0x562cd24b5e20
[DEBUG] [2021-07-20T15:09:41Z] [00007f42d3eae780] [mqtt-client] - client=0x562cd24c9920: Initalizing MQTT client
[INFO] [2021-07-20T15:09:41Z] [00007f42d3eae780] [tls-handler] - ctx: cannot enable ocsp stapling: OCSP stapling was requested, but is not supported
[DEBUG] [2021-07-20T15:09:41Z] [00007f42d3eae780] [tls-handler] - ctx: Setting ALPN list x-amzn-mqtt-ca
[DEBUG] [2021-07-20T15:09:41Z] [00007f42d3eae780] [mqtt-client] - id=0x562cd260e3f0: Creating new connection
[DEBUG] [2021-07-20T15:09:41Z] [00007f42d3eae780] [mqtt-topic-tree] - tree=0x562cd260e658: Creating new topic tree
[DEBUG] [2021-07-20T15:09:41Z] [00007f42d3eae780] [mqtt-client] - id=0x562cd260e3f0: Begin connecting process, switch state to CONNECTING.
[INFO] [2021-07-20T15:09:41Z] [00007f42d3eae780] [mqtt-client] - id=0x562cd260e3f0: using ping timeout of 3000000000 ns
[DEBUG] [2021-07-20T15:09:41Z] [00007f42d3eae780] [dns] - id=0x562cd24d78f0: Host resolution requested for foo-ats.iot.eu-west-1.amazonaws.com
[DEBUG] [2021-07-20T15:09:41Z] [00007f42d3eae780] [dns] - id=0x562cd24d78f0: No cached entries found for foo-ats.iot.eu-west-1.amazonaws.com starting new resolver thread.
[DEBUG] [2021-07-20T15:09:41Z] [00007f42d0892640] [dns] - static: resolving host foo-ats.iot.eu-west-1.amazonaws.com
[ERROR] [2021-07-20T15:09:41Z] [00007f42d0892640] [dns] - static: getaddrinfo failed with error_code -2
[WARN] [2021-07-20T15:09:41Z] [00007f42d0892640] [dns] - static, resolving host foo-ats.iot.eu-west-1.amazonaws.com failed, ec 1059 (aws-c-io: AWS_IO_DNS_INVALID_NAME, Host name was invalid for dns resolution.)
[DEBUG] [2021-07-20T15:09:41Z] [00007f42d0892640] [dns] - static, invoking resolution callback for host foo-ats.iot.eu-west-1.amazonaws.com with failure
[ERROR] [2021-07-20T15:09:41Z] [00007f42d0892640] [channel-bootstrap] - id=0x562cd219f4c0: dns resolution failed, or all socket connections to the endpoint failed.
[DEBUG] [2021-07-20T15:09:41Z] [00007f42d0892640] [channel-bootstrap] - id=0x562cd219f4c0: releasing bootstrap reference
node:events:371
      throw er; // Unhandled 'error' event
      ^

CrtError: Failed to connect: aws-c-io: AWS_IO_DNS_INVALID_NAME, Host name was invalid for dns resolution.
    at /home/m/nrf-asset-tracker/aws/node_modules/aws-crt/dist/native/mqtt.js:333:36
    at processTicksAndRejections (node:internal/process/task_queues:78:11)
Emitted 'error' event on MqttClientConnection instance at:
    at MqttClientConnection.emit (/home/m/nrf-asset-tracker/aws/node_modules/aws-crt/dist/common/event.js:75:22)
    at /home/m/nrf-asset-tracker/aws/node_modules/aws-crt/dist/native/mqtt.js:333:22
    at processTicksAndRejections (node:internal/process/task_queues:78:11) {
  error: 'Failed to connect: aws-c-io: AWS_IO_DNS_INVALID_NAME, Host name was invalid for dns resolution.',
  error_code: undefined,
  error_name: undefined
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
TingDaoKcommented, Aug 31, 2021

Turns out it’s not an actual bug. The connection is an EventEmitter, and once error happens, the error event will be invoked. And you need to handle that as well. But, to be honest, I am not a JS developer, that does seem a bit weird to me.

1reaction
coderbyheartcommented, Aug 31, 2021

Note that I intentionally set an invalid hostname in the example so it triggers this error. In my code I use the correct ATS hostname.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - Uncatchable exception thrown by calling Stage.show()
I just performed a couple of experiments: throwing first a RuntimeException and then a standard Exception in this attachAndShow() method, ...
Read more >
Uncatchable exception thrown when connecting with an ...
Hi, I've ran into an issue where when I attempt to set up a message listener on an RMQDestination with an invalid destname...
Read more >
Uncatchable exception thrown in MqttClientConnection ...
If connect() fails an uncatchable exception is thrown. I am using JITP for our devices, but when connecting using the AWS IoT SDK...
Read more >
Exception Handling - AWS SDK for Java 1.x
For example, the AWS SDK for Java throws an AmazonClientException if no network connection is available when you try to call an operation...
Read more >
Unchecked Exceptions — The Controversy
Any Exception that can be thrown by a method is part of the method's public programming interface. Those who call a method must...
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