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.

await connection.connect() results in a segfault

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

await connection.connect(); results in a segfault:

Signal received: -1050417728, errno: 32521
################################################################################
Resolved stacktrace:
################################################################################
0x00007f09c17c40cb: ?? ??:0
0x00000000000b1b03: s_print_stack_trace at module.c:?
0x00000000000153c0: __restore_rt at ??:?
0x00007f09c17a64e1: ?? ??:0
0x00007f09c176e5b4: ?? ??:0
0x00000000001134ac: s_drive_negotiation at s2n_tls_channel_handler.c:?
0x0000000000106b98: s_on_client_channel_on_setup_completed at channel_bootstrap.c:?
0x0000000000105b42: s_on_channel_setup_complete at channel.c:?
0x000000000017b6ee: s_run_all at task_scheduler.c:?
0x000000000010cf88: s_main_loop at epoll_event_loop.c:?
0x00000000001794cb: thread_fn at thread.c:?
0x0000000000009609: start_thread at ??:?
0x00007f09c4536293: ?? ??:0
################################################################################
Raw stacktrace:
################################################################################
/home/ubuntu/persist/code/toolshed/connection-hub-lite/node_modules/aws-crt/dist/bin/linux-x64/aws-crt-nodejs.node(aws_backtrace_print+0x4b) [0x7f09c17c40cb]
/home/ubuntu/persist/code/toolshed/connection-hub-lite/node_modules/aws-crt/dist/bin/linux-x64/aws-crt-nodejs.node(+0xb1b03) [0x7f09c16fcb03]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x153c0) [0x7f09c461b3c0]
/home/ubuntu/persist/code/toolshed/connection-hub-lite/node_modules/aws-crt/dist/bin/linux-x64/aws-crt-nodejs.node(s2n_client_hello_send+0x1e1) [0x7f09c17a64e1]
/home/ubuntu/persist/code/toolshed/connection-hub-lite/node_modules/aws-crt/dist/bin/linux-x64/aws-crt-nodejs.node(s2n_negotiate+0x334) [0x7f09c176e5b4]
/home/ubuntu/persist/code/toolshed/connection-hub-lite/node_modules/aws-crt/dist/bin/linux-x64/aws-crt-nodejs.node(+0x1134ac) [0x7f09c175e4ac]
/home/ubuntu/persist/code/toolshed/connection-hub-lite/node_modules/aws-crt/dist/bin/linux-x64/aws-crt-nodejs.node(+0x106b98) [0x7f09c1751b98]
/home/ubuntu/persist/code/toolshed/connection-hub-lite/node_modules/aws-crt/dist/bin/linux-x64/aws-crt-nodejs.node(+0x105b42) [0x7f09c1750b42]
/home/ubuntu/persist/code/toolshed/connection-hub-lite/node_modules/aws-crt/dist/bin/linux-x64/aws-crt-nodejs.node(+0x17b6ee) [0x7f09c17c66ee]
/home/ubuntu/persist/code/toolshed/connection-hub-lite/node_modules/aws-crt/dist/bin/linux-x64/aws-crt-nodejs.node(+0x10cf88) [0x7f09c1757f88]
/home/ubuntu/persist/code/toolshed/connection-hub-lite/node_modules/aws-crt/dist/bin/linux-x64/aws-crt-nodejs.node(+0x1794cb) [0x7f09c17c44cb]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x9609) [0x7f09c460f609]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x43) [0x7f09c4536293]

SDK version number “aws-crt”: “^1.3.0”, “aws-iot-device-sdk-v2”: “^1.3.1”,

Platform/OS/Hardware/Device Ubuntu 20.04 LTS

To Reproduce (observed behavior)

I’ve adapted the pub/sub example. I’ve verified the option value by using Mqtt.fx to successfully connect with the same configuration.

  const configBuilder = iot.AwsIotMqttConnectionConfigBuilder.new_mtls_builder_from_path(
    options.cert, options.key,
  );
  configBuilder.with_certificate_authority_from_path(undefined, options.ca_file);

  configBuilder.with_clean_session(false);
  configBuilder.with_client_id(options.client_id);
  configBuilder.with_endpoint(options.endpoint);

  const config = configBuilder.build();
  const client = new mqtt.MqttClient(clientBootstrap);
  const connection = client.new_connection(config);

  await connection.connect();

Steps to reproduce the behavior (please share code)

Expected behavior

I’d expect it to connect, but it doesn’t. And the error doesn’t seem to indicate what is causing the segfault to me.

Logs/output

(See report)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:11

github_iconTop GitHub Comments

4reactions
thomasmichaelwallacecommented, Oct 18, 2020

Sure @EyalSi - you can use mqtt for the connection to IoT Core.

/* eslint-disable no-console */
const mqtt = require('mqtt');
const fs = require('fs');

const options = {
  key: fs.readFileSync('path-to-key-file'),
  cert: fs.readFileSync('path-to-cert-file'),
  ca: fs.readFileSync('path-to-ca-file'),
};

async function main() {
  const client = mqtt.connect('mqtt://your-iot-account-ats.iot.region.amazonaws.com', options);

  client.on('connect', () => {
    client.subscribe(['a/topic/here', 'another/topic/+/here'], (err) => {
      if (!err) {
        console.log('connected');
      } else {
        console.error('failed to connect', err);
      }
    });
  });

  client.on('message', async (topic, message) => {
    const event = { topic, message: JSON.parse(message.toString()) };
    console.log(JSON.stringify(event));
  });

  // if/when you need to close:
  // client.end();
}
main()

(You can use the aws-sdk-js IoT namespace, https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Iot.html, to do all the service stuff like creating rules, retc.)

1reaction
thomasmichaelwallacecommented, Feb 26, 2021

@bharring - probably worth noting that this issue is quite old now and wasn’t ever noticed by the maintainers.

You might have better luck opening a new issue (then again, you might not, who knows with AWS’ open source projects!).

I will say, though, that this SDK doesn’t really add that much, given the amount of confusion and debugging/deployment-difficulty it introduces by using C bindings.

Alternatively, both the node mqtt and aws-sdk libraries are well maintained, are in native javascript, and have larger communities. I suspect you will get more mileage out of using the approach I outlined in my workaround.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Segmentation Fault when calling class functions in async
What I wanted to do is to basically dynamically create an object of Loop and an async function which calls the start method...
Read more >
Random segfaults with async/await, but only on release builds
I have a Vapor application that is experiencing random segmentation faults, but only when built with -c release.
Read more >
1319165 – goferd close_wait leak and occasional segfault ...
Description of problem: Restarting qpidd on Satellite, goferd / proton reactor does not close the FD for the socket of the TCP connection...
Read more >
How to Debug Node.js Segmentation Faults - HTTP Toolkit
A segmentation fault occurs when a program attempts to access a memory location that it is not allowed to access, or attempts to...
Read more >
I'm an Expert in Memory Management & Segfaults, Ask Me ...
There are only two ways to debug a segmentation fault, ordinarily: 1) If you have access to the source code for ros-kinetic, you...
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