aws-iot-device-sdk-js-v2: Websocket setup failed to establish HTTP connection, error 1029 (AWS_IO_TLS_ERROR_NEGOTIATION_FAILURE)

Confirm by changing [ ] to [x] below to ensure that it’s a bug:

Describe the bug A clear and concise description of what the bug is. Can’t connect to IoT message broker

SDK version number

    "aws-crt": "^1.0.6",
    "aws-iot-device-sdk-v2": "^1.0.4",
    "aws-sdk": "^2.643.0",

Platform/OS/Hardware/Device What are you running the sdk on? linux (arch-linux 5.5.13-arch1-1)

To Reproduce (observed behavior)

const client_bootstrap = new io.ClientBootstrap();

const config_builder = iot.AwsIotMqttConnectionConfigBuilder.new_with_websockets({
    credentials_provider: auth.AwsCredentialsProvider.newDefault(client_bootstrap),
    region: AWS_REGION,
});

config_builder.with_clean_session(false);
config_builder.with_client_id(uuid());
config_builder.with_endpoint(`data.iot.${AWS_REGION}.amazonaws.com`);

const config = config_builder.build();
const client = new mqtt.MqttClient(client_bootstrap);
const connection = client.new_connection(config);

const topic = `tournaments`;

const subscribe = async () => {
    const connected = await connection.connect();
    if (!connected) {
        throw Error('IoT connection failed!');
    }
    console.log(`Subscribe to ${topic}`);
    const request = await connection.subscribe(topic, mqtt.QoS.AtLeastOnce, (_, payload) => {
        const events: ChangeEvent[] = JSON.parse(payload.toString());
        console.log(events);
        processChangeEvents(events);
    });
    console.log(request);
};

subscribe();

Expected behavior A clear and concise description of what you expected to happen. for client to subscribe to topic

Logs/output If applicable, add logs or error output.

[ERROR] [2020-03-30T18:38:27Z] [00007efbe7fff700] [socket] - id=0x7efbe0004ca0 fd=26: connect failed with error code 101.
[ERROR] [2020-03-30T18:38:27Z] [00007efbe7fff700] [channel-bootstrap] - id=0x4dc8910: failed to create socket with error 1049
[ERROR] [2020-03-30T18:38:27Z] [00007efbe7fff700] [channel-bootstrap] - id=0x4dc8910: channel 0x7efbe0005320 setup failed with error 1029.
[ERROR] [2020-03-30T18:38:27Z] [00007efbe7fff700] [Unknown] - static: Client connection failed with error 1029 (AWS_IO_TLS_ERROR_NEGOTIATION_FAILURE).
[ERROR] [2020-03-30T18:38:27Z] [00007efbe7fff700] [Unknown] - id=0x4e351c0: Websocket setup failed to establish HTTP connection, error 1029 (AWS_IO_TLS_ERROR_NEGOTIATION_FAILURE).
N-API call failed: napi_call_function(env, this_ptr, function, argc, argv, NULL)
    @ /root/aws-crt-nodejs/source/module.c:376: napi_pending_exception
Calling (error_code, return_code, session_present) => {
                    if (error_code == 0 && return_code == 0) {
                        resolve(session_present);
                        this.emit('connect', session_present);
                    }
                    else if (error_code != 0) {
                        reject("Failed to connect: " + io.error_code_to_string(error_code));
                    }
                    else {
                        reject("Server rejected connection.");
                    }
                }
Error: Failed to connect: aws-c-io: AWS_IO_TLS_ERROR_NEGOTIATION_FAILURE, TLS (SSL) negotiation failed
Stack:
Error: Failed to connect: aws-c-io: AWS_IO_TLS_ERROR_NEGOTIATION_FAILURE, TLS (SSL) negotiation failed
    at /home/batja/Projects/xpresshd/project-a/public-api/node_modules/aws-crt/lib/native/mqtt.ts:288:32
    at on_connect (/home/batja/Projects/xpresshd/project-a/public-api/node_modules/aws-crt/lib/native/mqtt.ts:140:21)
N-API call failed: aws_napi_dispatch_threadsafe_function(env, args->on_connect, NULL, on_connect, num_params, params)
    @ /root/aws-crt-nodejs/source/mqtt_client_connection.c:299: napi_pending_exception
Fatal error condition occurred in /root/aws-crt-nodejs/source/mqtt_client_connection.c:299: aws_napi_dispatch_threadsafe_function(env, args->on_connect, NULL, on_connect, num_params, params)
Exiting Application
################################################################################
Resolved stacktrace:
################################################################################
0x00007efbfc48ba0b: ?? ??:0
0x00007efbfc483233: ?? ??:0
0x00000000000d2c95: s_on_connect_call at mqtt_client_connection.c:?
0x00000000009880a5: _ZN6v8impl12_GLOBAL__N_118ThreadSafeFunction6IdleCbEP9uv_idle_s at node_api.cc:?
0x000000000127517c: uv__run_idle at loop-watcher.c:68 (discriminator 4)
0x000000000126de18: uv_run at core.c:362
0x00000000009f13dc: _ZN4node16NodeMainInstance3RunEv at ??:?
0x0000000000986911: _ZN4node5StartEiPPc at ??:?
0x00007efbff16a023: ?? ??:0
0x0000000000924865: _start at ??:?
################################################################################
Raw stacktrace:
################################################################################
/home/batja/Projects/xpresshd/project-a/public-api/node_modules/aws-crt/dist/bin/linux-x64/aws-crt-nodejs.node(aws_backtrace_print+0x4b) [0x7efbfc48ba0b]
/home/batja/Projects/xpresshd/project-a/public-api/node_modules/aws-crt/dist/bin/linux-x64/aws-crt-nodejs.node(aws_fatal_assert+0x43) [0x7efbfc483233]
/home/batja/Projects/xpresshd/project-a/public-api/node_modules/aws-crt/dist/bin/linux-x64/aws-crt-nodejs.node(+0xd2c95) [0x7efbfc3fcc95]
/home/batja/.nvm/versions/node/v12.6.0/bin/node() [0x9880a5]
/home/batja/.nvm/versions/node/v12.6.0/bin/node() [0x127517c]
/home/batja/.nvm/versions/node/v12.6.0/bin/node(uv_run+0x368) [0x126de18]
/home/batja/.nvm/versions/node/v12.6.0/bin/node(_ZN4node16NodeMainInstance3RunEv+0x2ec) [0x9f13dc]
/home/batja/.nvm/versions/node/v12.6.0/bin/node(_ZN4node5StartEiPPc+0x291) [0x986911]
/usr/lib/libc.so.6(__libc_start_main+0xf3) [0x7efbff16a023]
/home/batja/.nvm/versions/node/v12.6.0/bin/node() [0x924865]
Signal received: 0, errno: 0
################################################################################
Resolved stacktrace:
################################################################################
0x00007efbfc48ba0b: ?? ??:0
0x00000000000d0d83: s_print_stack_trace at module.c:?
0x0000000000014800: __restore_rt at sigaction.c:?
0x00007efbff17ece5: ?? ??:0
0x00007efbff168857: ?? ??:0
0x0000000000159238: aws_fatal_assert at ??:?
0x00000000000d2c95: s_on_connect_call at mqtt_client_connection.c:?
0x00000000009880a5: _ZN6v8impl12_GLOBAL__N_118ThreadSafeFunction6IdleCbEP9uv_idle_s at node_api.cc:?
0x000000000127517c: uv__run_idle at loop-watcher.c:68 (discriminator 4)
0x000000000126de18: uv_run at core.c:362
0x00000000009f13dc: _ZN4node16NodeMainInstance3RunEv at ??:?
0x0000000000986911: _ZN4node5StartEiPPc at ??:?
0x00007efbff16a023: ?? ??:0
0x0000000000924865: _start at ??:?
################################################################################
Raw stacktrace:
################################################################################
/home/batja/Projects/xpresshd/project-a/public-api/node_modules/aws-crt/dist/bin/linux-x64/aws-crt-nodejs.node(aws_backtrace_print+0x4b) [0x7efbfc48ba0b]
/home/batja/Projects/xpresshd/project-a/public-api/node_modules/aws-crt/dist/bin/linux-x64/aws-crt-nodejs.node(+0xd0d83) [0x7efbfc3fad83]
/usr/lib/libpthread.so.0(+0x14800) [0x7efbff31f800]
/usr/lib/libc.so.6(gsignal+0x145) [0x7efbff17ece5]
/usr/lib/libc.so.6(abort+0x12b) [0x7efbff168857]
/home/batja/Projects/xpresshd/project-a/public-api/node_modules/aws-crt/dist/bin/linux-x64/aws-crt-nodejs.node(+0x159238) [0x7efbfc483238]
/home/batja/Projects/xpresshd/project-a/public-api/node_modules/aws-crt/dist/bin/linux-x64/aws-crt-nodejs.node(+0xd2c95) [0x7efbfc3fcc95]
/home/batja/.nvm/versions/node/v12.6.0/bin/node() [0x9880a5]
/home/batja/.nvm/versions/node/v12.6.0/bin/node() [0x127517c]
/home/batja/.nvm/versions/node/v12.6.0/bin/node(uv_run+0x368) [0x126de18]
/home/batja/.nvm/versions/node/v12.6.0/bin/node(_ZN4node16NodeMainInstance3RunEv+0x2ec) [0x9f13dc]
/home/batja/.nvm/versions/node/v12.6.0/bin/node(_ZN4node5StartEiPPc+0x291) [0x986911]
/usr/lib/libc.so.6(__libc_start_main+0xf3) [0x7efbff16a023]
/home/batja/.nvm/versions/node/v12.6.0/bin/node() [0x924865]
const level : io.LogLevel = parseInt(io.LogLevel[argv.verbosity.toUpperCase()]);
io.enable_logging(level);

Additional context Add any other context about the problem here.

Using node v12.6.0

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 3
  • Comments: 27 (8 by maintainers)

Most upvoted comments

@reinismu I just stopped using the v2 SDK 👎 and went back to the way easier to use and definitely working v1 SDK 👍

Any updates?

I tried again with newer versions. I noticed if I put constant client_id and run it twice (first time still wouldn’t work) it will work the second time.

Code

    const client_bootstrap = new io.ClientBootstrap();
    
    const config_builder = iot.AwsIotMqttConnectionConfigBuilder.new_with_websockets({
        credentials_provider: auth.AwsCredentialsProvider.newDefault(client_bootstrap),
        region: AWS_REGION,
    });
    
    config_builder.with_clean_session(false);
    config_builder.with_client_id("some_constant_string");
    config_builder.with_endpoint(`<stuff>-ats.iot.eu-central-1.amazonaws.com`);
    
    const config = config_builder.build();
    const client = new mqtt.MqttClient(client_bootstrap);
    const connection = client.new_connection(config);

    const topic = `${RESOURCE_PREFIX}tournaments`;

    const connected = await connection.connect();
    if (!connected) {
        throw Error('IoT connection failed!');
    }
    console.log(`Subscribe to ${topic}`);
    const request = await connection.subscribe(topic, mqtt.QoS.AtLeastOnce, (_, payload) => {
        const events: TournamentChangeEvent[] = JSON.parse(payload.toString());
        console.log(events);
        processTournamentChangeEvents(events);
    });
    console.log(request);

First time output

[ERROR] [2020-06-08T07:05:59Z] [00007f028b9c4700] [socket] - id=0x7f0284004ca0 fd=26: connect failed with error code 101.
[ERROR] [2020-06-08T07:05:59Z] [00007f028b9c4700] [channel-bootstrap] - id=0x3457ed0: failed to create socket with error 1049
(node:9091) UnhandledPromiseRejectionWarning: Error: IoT connection failed!
    at subscribe (/home/batka/projects/public-api/src/resolvers/subscriptions.ts:118:15)
(node:9091) 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:9091) [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.

Second time output and it seems to be working

[ERROR] [2020-06-08T07:06:02Z] [00007f60fe9c2700] [socket] - id=0x7f60ec004ca0 fd=26: connect failed with error code 101.
[ERROR] [2020-06-08T07:06:02Z] [00007f60fe9c2700] [channel-bootstrap] - id=0x479c4d0: failed to create socket with error 1049
Subscribe to test-tournaments
{ packet_id: 1, topic: 'test-tournaments', qos: 1, error_code: 0 }

In any case I want to use random uuid() for client ID’s and need just the pub sub functionality out of IoT.