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

Electron: Segfault aws_napi_queue_threadsafe_function #335

Closed
mfoti opened this issue Mar 2, 2023 · 7 comments
Closed

Electron: Segfault aws_napi_queue_threadsafe_function #335

mfoti opened this issue Mar 2, 2023 · 7 comments
Labels
feature-request A feature should be added or improved. p2 This is a standard priority issue

Comments

@mfoti
Copy link

mfoti commented Mar 2, 2023

Describe the bug

I've tried to execute the MQTT5 example inside an electron project and the publish command crashes with a segfault, below the stack trace. I don't know if it's a bug of aws-crt-nodejs but I run the same lib for cloudwatch without problems.

QoS 1 Publish result: {"type":4,"reasonCode":0,"userProperties":[]}
Signal received: 6, errno: 0
################################################################################
Stack trace:
################################################################################
1   aws-crt-nodejs.node                 0x000000011611440c s_print_stack_trace + 24
2   libsystem_platform.dylib            0x00000001ab4e14c4 _sigtramp + 56
3   libsystem_pthread.dylib             0x00000001ab4c9ee0 pthread_kill + 288
4   libsystem_c.dylib                   0x00000001ab404340 abort + 168
5   Electron Framework                  0x000000010d778058 uv_cond_signal + 0
6   Electron Framework                  0x0000000113abf5bc napi_acquire_threadsafe_function + 36
7   aws-crt-nodejs.node                 0x0000000116113578 aws_napi_queue_threadsafe_function + 28
8   aws-crt-nodejs.node                 0x0000000116116ca0 s_lifecycle_event_callback + 756
9   aws-crt-nodejs.node                 0x000000011615a0e4 s_aws_mqtt5_client_emit_final_lifecycle_event + 304
10  aws-crt-nodejs.node                 0x00000001161559fc s_mqtt5_service_task_fn + 668
11  aws-crt-nodejs.node                 0x00000001161b1954 s_run_all + 312
12  aws-crt-nodejs.node                 0x000000011617cce0 aws_event_loop_thread + 1640
13  aws-crt-nodejs.node                 0x00000001161af89c thread_fn + 348
14  libsystem_pthread.dylib             0x00000001ab4ca26c _pthread_start + 148
15  libsystem_pthread.dylib             0x00000001ab4c508c thread_start + 8

Expected Behavior

no errors

Current Behavior

it crashes

Reproduction Steps

call client.publish inside an electron main process

Possible Solution

No response

Additional Information/Context

No response

SDK version used

1.9.5

Environment details (OS name and version, etc.)

all (windows, linux, osx)

@mfoti mfoti added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Mar 2, 2023
@bretambrose
Copy link
Contributor

Unfortunately, we don't support running in Electron at the moment. It's tentatively planned for later this year.

@jmklix jmklix added feature-request A feature should be added or improved. p2 This is a standard priority issue and removed bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Mar 2, 2023
@jmklix jmklix changed the title Segfault aws_napi_queue_threadsafe_function Electron: Segfault aws_napi_queue_threadsafe_function Mar 3, 2023
@mfoti
Copy link
Author

mfoti commented Mar 4, 2023

is there any workaround tu subscribe to an AWS IoT MQTT topic? For example using a standard lib?

@bretambrose
Copy link
Contributor

Looking closer, I think I misdiagnosed. We're aware of a dynamic loading failure on Windows with Electron, but this isn't that. Can you provide full detailed repro steps (linux preferred)? Assume I know nothing about Electron (which would be a correct assumption).

The crash isn't in publish. It appears that Node is going away before the native code is completely finished. There may be some relaxations we can apply to how we use the threadsafe functions to handle this.

As for workarounds, you can use the v1 SDK for mqtt3. You can use a third party mqtt library directly, but correctly handling authentication can be tricky depending on what you want to do (cert/key vs. websockets with sigv4 signing vs. custom authentication).

@memo26167
Copy link

Hi @bretambrose . Recently, I've tried to implement electron with quasar. I used the recent greengrasscoreipc and the app crashes when trying to publish a payload. I've used the gg_ipc as reference and I think the error is similar:

N-API call failed: napi_create_external_arraybuffer( env, data_buffer->buffer, data_buffer->len, s_finalize_external_binary_byte_buf, data_buffer, &napi_binary).
@ /aws-crt-nodejs/source/module.c:269: UNKNOWN.
Fatal error condition occurred in /aws-crt-nodejs/source/module.c:269: napi_create_external_arraybuffer( env, data_buffer->buffer, data_buffer->len, s_finalize_external_binary_byte_buf, data_buffer, &napi_binary).
Exiting Application. 

@xiazhvera
Copy link
Contributor

Hi @bretambrose . Recently, I've tried to implement electron with quasar. I used the recent greengrasscoreipc and the app crashes when trying to publish a payload. I've used the gg_ipc as reference and I think the error is similar:

N-API call failed: napi_create_external_arraybuffer( env, data_buffer->buffer, data_buffer->len, s_finalize_external_binary_byte_buf, data_buffer, &napi_binary).
@ /aws-crt-nodejs/source/module.c:269: UNKNOWN.
Fatal error condition occurred in /aws-crt-nodejs/source/module.c:269: napi_create_external_arraybuffer( env, data_buffer->buffer, data_buffer->len, s_finalize_external_binary_byte_buf, data_buffer, &napi_binary).
Exiting Application. 

Hi @memo26167 , I think what you mentioned above is a different issue. As Electron no longer supports napi_create_external_arraybuffer since v20.3.9, the app would crash on that API. We are looking for a way around, while we don't have any progress yet. We made a quick test on Electron@19 and it worked so far. You could probably try Electron@19 as for now.
If you are interested, you can find more discussion from the community about the issue at electron/electron#35801

@xiazhvera
Copy link
Contributor

We have updated the Electron support. The issue should be fixed in release v1.19.1. https://github.com/aws/aws-iot-device-sdk-js-v2/releases/tag/v1.19.1

Copy link

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A feature should be added or improved. p2 This is a standard priority issue
Projects
None yet
Development

No branches or pull requests

5 participants