JCMais / node-libcurl

libcurl bindings for Node.js
https://npmjs.org/package/node-libcurl
MIT License
666 stars 118 forks source link

Segmentation fault on aarch64 #335

Closed jhoogstraat closed 2 years ago

jhoogstraat commented 2 years ago

I got a segmentation fault using the library on my raspi 4 in a docker container. segfault-handler reported the following stacktrace:

PID 54 received SIGSEGV for address: 0x1000001b7
/bot/node_modules/segfault-handler/build/Release/segfault-handler.node(+0x2b54)[0x7f81183b54]
linux-vdso.so.1(__kernel_rt_sigreturn+0x0)[0x7f927cd7d8]
/usr/lib/aarch64-linux-gnu/libssl.so.1.1(SSL_get_peer_certificate+0x18)[0x7f721f3f58]
/usr/lib/aarch64-linux-gnu/libcurl.so.4(+0x662d8)[0x7f723022d8]
/usr/lib/aarch64-linux-gnu/libcurl.so.4(+0x6995c)[0x7f7230595c]
/usr/lib/aarch64-linux-gnu/libcurl.so.4(+0x6a7c4)[0x7f723067c4]
/usr/lib/aarch64-linux-gnu/libcurl.so.4(+0x2d2ac)[0x7f722c92ac]
/usr/lib/aarch64-linux-gnu/libcurl.so.4(+0x42790)[0x7f722de790]
/usr/lib/aarch64-linux-gnu/libcurl.so.4(+0x439fc)[0x7f722df9fc]
/usr/lib/aarch64-linux-gnu/libcurl.so.4(curl_multi_socket_action+0x30)[0x7f722dfb84]
/bot/node_modules/node-libcurl/lib/binding/node_libcurl.node(_ZN11NodeLibcurl5Multi9OnTimeoutEP10uv_timer_s+0x120)[0x7f901bdc00]
node[0x14fb418]
node(uv_run+0x78)[0x14ff820]
node(_ZN4node13SpinEventLoopEPNS_11EnvironmentE+0x124)[0xa6998c]
node(_ZN4node16NodeMainInstance3RunEPKNS_16EnvSerializeInfoE+0x168)[0xb5a178]
node(_ZN4node5StartEiPPc+0x1dc)[0xae656c]
/lib/aarch64-linux-gnu/libc.so.6(__libc_start_main+0xe8)[0x7f9235f218]
node[0xa67cf4]
Segmentation fault

The error occurs only on aarch64, x86 works fine. This test script exhibits the segmentation fault:

import { curly } from "node-libcurl";

async function req(url: string): Promise<any> {
  console.log(url)
  const response = await curly.get(url, { verbose: true })
  console.log("Response from", url)
  return response.data
}

const res = await req('https://google.com')
console.log(res)

const arr = [1, 2, 3, 4].forEach(async element => {
  const res = await req('https://google.com')
  console.log(element, res)
});

console.log("Finished")

The use case in the application is equivalent to the forEach example shown above, but the single request before already proeduces the seg fault.

The circumstances are very specific, but I try my best to completely describe the situation


EDIT 1: The error occurs because node17 updated openssl to 3.0.0, which is no compatible with the system version (1.1.1k). Downgrading to Node16, which still uses 1.1.1 works.

JCMais commented 2 years ago

I suppose you had to build the addon from source, right?

This is probably the same issue described on #164. Basically, if you are building from the source, you must build the addon using the same OpenSSL version as the one used by Node.js itself. For more context please see the original issue. It is not something that can be easily fixed from the add-on side.

jhoogstraat commented 2 years ago

Yeah, that was it. Didn't knew that node updated OpenSSL.

I guess this issue can still purpose as a guideline for user with the same issues on arm.