apache / pulsar-client-node

Apache Pulsar NodeJS Client
https://pulsar.apache.org/
Apache License 2.0
148 stars 86 forks source link

Client segfaults when creating/destroying readers with listener callbacks repeatedly #374

Closed roryschadler closed 7 months ago

roryschadler commented 7 months ago

I found that when I created and immediately closed readers a couple times in a row, the client would fail with a segfault. I'm not familiar with the C++ lib underpinning this client, but it appears to be due to the listener callback.

Segfault stack:

PID 57514 received SIGSEGV for address: 0x10
0   segfault-handler.node               0x000000010624cef8 _ZL16segfault_handleriP9__siginfoPv + 296
1   libsystem_platform.dylib            0x0000000185537584 _sigtramp + 56
2   pulsar.node                         0x0000000119e136a8 _Z19ReaderListenerProxyN4Napi3EnvENS_8FunctionEP23ReaderListenerProxyData + 92
3   pulsar.node                         0x0000000119df41a8 _ZN4Napi18ThreadSafeFunction6CallJSEP10napi_env__P12napi_value__PvS5_ + 68
4   node                                0x000000010095edc4 _ZN6v8impl12_GLOBAL__N_118ThreadSafeFunction7AsyncCbEP10uv_async_s + 440
5   node                                0x000000010135d868 uv__async_io + 268
6   node                                0x000000010136f940 uv__io_poll + 1020
7   node                                0x000000010135de2c uv_run + 476
8   node                                0x00000001008c1754 _ZN4node21SpinEventLoopInternalEPNS_11EnvironmentE + 256
9   node                                0x00000001009ce63c _ZN4node16NodeMainInstance3RunEPNS_8ExitCodeEPNS_11EnvironmentE + 164
10  node                                0x00000001009ce3d8 _ZN4node16NodeMainInstance3RunEv + 124
11  node                                0x0000000100959494 _ZN4node5StartEiPPc + 776
12  dyld                                0x000000018517e0e0 start + 2360

(collected using https://www.npmjs.com/package/segfault-handler)

Reproduction: https://github.com/roryschadler/pulsar-client-segfault-repro

roryschadler commented 7 months ago

Reproduction: https://github.com/roryschadler/pulsar-client-segfault-repro/blob/2ad9eeab2ceb86e863f4c13439f744c88a46d2a5/index.js

merlimat commented 7 months ago

1.11 release is going out. It might be worth trying with it.

You can find the pre-built binaries here: https://dist.apache.org/repos/dist/dev/pulsar/pulsar-client-node/pulsar-client-node-1.11.0-rc.1 (or wait a couple of days until the release is officially announced)

roryschadler commented 7 months ago

I'll do that tomorrow, thanks @merlimat!

roryschadler commented 7 months ago

Unfortunately it still occurs with the release candidate. Updated the repro repo accordingly.

merlimat commented 7 months ago

@shibd Please take a look when you have the chance

shibd commented 7 months ago

This fix by #376

@roryschadler Can you update to 1.11.0-rc.3 to verify it?

npm i pulsar-client@1.11.0-rc.3 --pulsar_binary_host_mirror=https://dist.apache.org/repos/dist/dev/pulsar/pulsar-client-node
roryschadler commented 7 months ago

Verified! This resolves the segfault I was seeing. Thank you @shibd!