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.

Not catchable exceptions and C-style output not supressable

See original GitHub issue

Describe the bug Exceptions occuring in the v2 SDK (in the native code I guess) are not catchable, the native libraries write on its own to the console and crash. The situation cannot be properly handled in many cases by your NodeJS app. Overall this feels like a library for C, not for NodeJS.

Scenario A: After some time it disconnects with Ping-Timeout. Not possible to catch to reconnecct.

[ERROR] [2020-04-28T21:56:55Z] [00004d24] [mqtt-client] - id=000001D114281670: ping timeout detected
[ERROR] [2020-04-28T21:56:55Z] [00004d24] [socket] - id=000001D1142AFC50 handle=0000000000000450: connect completion triggered with error -1073741305
[ERROR] [2020-04-28T21:56:55Z] [00004d24] [socket] - id=000001D1142AFC50 handle=0000000000000450: connection error with code 1055
** Exception 0xc0000005 occured **
at 0x7FFA5A64C6D0: napi_register_module_v1
at 0x7FFA5A64C6D0: napi_register_module_v1
at 0x7FFA71DFFD00: UnhandledExceptionFilter
at 0x7FFA73FA2F80: memset
at 0x7FFA73F8C5C0: _C_specific_handler
at 0x7FFA73FA10B0: _chkstk
at 0x7FFA73F69E70: RtlRaiseException
at 0x7FFA73F9FE10: KiUserExceptionDispatcher
at 0x7FFA73F071E0: RtlDllShutdownInProgress
at 0x7FFA73F1B380: RtlEnterCriticalSection
at 0x7FFA73F1B380: RtlEnterCriticalSection
at 0x7FF7AA3EAB60: napi_acquire_threadsafe_function
at 0x7FFA5A64C6D0: napi_register_module_v1
at 0x7FFA5A64C6D0: napi_register_module_v1
at 0x7FFA5A64C6D0: napi_register_module_v1
at 0x7FFA5A64C6D0: napi_register_module_v1
at 0x7FFA5A64C6D0: napi_register_module_v1
at 0x7FFA5A64C6D0: napi_register_module_v1
at 0x7FFA5A64C6D0: napi_register_module_v1
at 0x7FFA5A64C6D0: napi_register_module_v1
at 0x7FFA5A64C6D0: napi_register_module_v1
at 0x7FFA5A64C6D0: napi_register_module_v1
at 0x7FFA5A64C6D0: napi_register_module_v1
at 0x7FFA5A64C6D0: napi_register_module_v1
at 0x7FFA731D7BC0: BaseThreadInitThunk
at 0x7FFA73F6CE30: RtlUserThreadStart

Scenario B: On every connect I get erros on the console I cannot suppress but it works although these errors:

[ERROR] [2020-04-28T21:36:52Z] [00004d24] [socket] - id=000001D1142E48F0 handle=0000000000000388: connect completion triggered with error -1073741305
[ERROR] [2020-04-28T21:36:52Z] [00004d24] [socket] - id=000001D1142E48F0 handle=0000000000000388: connection error with code 1055

Scenario C: You mistakenly give a wrong filename:

[ERROR] [2020-04-29T16:05:05Z] [00005694] [file-utils] - static: Failed to open file config/badb237f72-certificatex.pem.crt with errno 2

Here no crash and an exception with a meaningful message you can catch. +1 for that, -1 for the unsupressable console log.

Scenario D: Give him a wrong key:

[ERROR] [2020-04-29T16:09:07Z] [00005e00] [socket] - id=00000241F8CEC5E0 handle=0000000000000390: connect completion triggered with error -1073741305
[ERROR] [2020-04-29T16:09:07Z] [00005e00] [socket] - id=00000241F8CEC5E0 handle=0000000000000390: connection error with code 1055
[ERROR] [2020-04-29T16:09:07Z] [00005e00] [tls-handler] - id=00000241F8D057B0: Error sending client/receiving server handshake data. SECURITY_STATUS is -2146893055
[ERROR] [2020-04-29T16:09:07Z] [00005e00] [channel-bootstrap] - id=00000241F8AC76B0: channel 00000241F8CF3240 setup failed with error 1029.
N-API call failed: napi_call_function(env, this_ptr, function, argc, argv, NULL)
    @ C:\Program Files (x86)\Jenkins\workspace\aws-crt-nodejs-build-dll-win64\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-common: AWS_ERROR_SYS_CALL_FAILURE, System call failure
Stack:
Error: Failed to connect: aws-c-common: AWS_ERROR_SYS_CALL_FAILURE, System call failure
    at E:\coding\aloxi\bridge\node_modules\aws-crt\dist\native\mqtt.js:241:32
    at on_connect (E:\coding\aloxi\bridge\node_modules\aws-crt\dist\native\mqtt.js:111:25)
N-API call failed: aws_napi_dispatch_threadsafe_function(env, args->on_connect, NULL, on_connect, num_params, params)
    @ C:\Program Files (x86)\Jenkins\workspace\aws-crt-nodejs-build-dll-win64\aws-crt-nodejs\source\mqtt_client_connection.c:300: napi_pending_exception
Fatal error condition occurred in C:\Program Files (x86)\Jenkins\workspace\aws-crt-nodejs-build-dll-win64\aws-crt-nodejs\source\mqtt_client_connection.c:300: aws_napi_dispatch_threadsafe_function(env, args->on_connect, NULL, on_connect, num_params, params)
Exiting Application
at 0x7FFA47CAC6D0: napi_register_module_v1
at 0x7FFA47CAC6D0: napi_register_module_v1
at 0x7FFA47CAC6D0: napi_register_module_v1
at 0x7FF7D8C49380: node_module_register
at 0x7FF7D8CC0CA0: uv_idle_init
at 0x7FF7D8CCB120: uv_run
at 0x7FF7D8BD30F0: EVP_CIPHER_CTX_buf_noconst
at 0x7FF7D8C50410: node::Start
at 0x7FF7D8A63900: RC4_options
at 0x7FF7D999EA90: v8::internal::compiler::RepresentationChanger::Uint32OverflowOperatorFor
at 0x7FFA731D7BC0: BaseThreadInitThunk
at 0x7FFA73F6CE30: RtlUserThreadStart

Crash, no exception, no possiblity to give a meaningful response or recover.

SDK version number 1.0.5

Platform/OS/Hardware/Device Windows 10 (1909), NodeJS 14.0.0, PC

To Reproduce (observed behavior) Packages aws-ios-device-sdk-v2, aws-crt, express. Use this TypeScript code, tsc && node .

Use this code but only one scenario function at a time: https://gist.github.com/ZoolWay/3acda0ca48ecd54e57f531d1d7914266

Expected behavior The native code should no write on its own. You should be able to provide callbacks to your logging framework to handle messages from the SDK like you would like them to appear.

Errors should throw exceptions with meaningful errors. C code stracktraces and memory dump parts should be opt-in or fetched on demand.

Logs/output Output in the description.

Additional context I appreciate the way to a more modern SDK but this feels too Alpha or too C 😉

Issue Analytics

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

github_iconTop GitHub Comments

4reactions
bretambrosecommented, Aug 18, 2020

Release 1.2.6 addresses this issue. Mqtt errors are now emitted from the node tick rather than during the NAPI call.

1reaction
jarredkennycommented, Jul 28, 2020

Adding my experience as support for work being done on this issue.

I am also running into a situation in my application where await connection.connect() errors but cannot be caught. In my case this brings down the entire application (electron, iot sdk invoked in main process).

Read more comments on GitHub >

github_iconTop Results From Across the Web

An example of how suppressed exceptions in Java work
The output generated when you run the main method is: The door is becoming unhinged! The door is now closed. Primary Exception: SwingException...
Read more >
Swift Error Handling For Methods That Do Not Throw [duplicate]
How to handle errors for methods or code that does not explicitly throw? Wrapping it a do / catch block results in a...
Read more >
Java Suppressed Exceptions | Baeldung
Starting with Java 7, we can now use two methods on the Throwable class to handle our suppressed exceptions: addSuppressed and getSuppressed.
Read more >
Modern C++ best practices for exceptions and error handling
In this article. Use exceptions for exceptional code; Basic guidelines; Exceptions and performance; Exceptions versus assertions ...
Read more >
PHP 8.0: @ Error Suppression operator does not silent fatal ...
While PHP is getting strict with better exception handling, ... In PHP 8.0, the @ operator does not suppress certain types of errors...
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