stellar / js-stellar-sdk

Main Stellar client library for the JavaScript language.
https://stellar.github.io/js-stellar-sdk/
Apache License 2.0
645 stars 314 forks source link

Keypair fromSecret causes Segmentation Fault in node alpine #798

Open bitgoAaron opened 2 years ago

bitgoAaron commented 2 years ago

Describe the bug Trying to use stellar-sdk's Keypair fromSecret function does not work in alpine flavors of linux.

What version are you on?

To Reproduce

Error Output:

npm ERR! path /srv
npm ERR! command failed
npm ERR! signal SIGSEGV
npm ERR! command sh -c -- node index.js

Expected behavior

Additional context

corymsmith commented 1 year ago

@bitgoAaron I was running into the same issues and managed to get it working on node 16 slim. I also installed build-essential using apt-get. The final image size didn't end up being that much larger.

1baga commented 1 year ago

Spent 3 days trying to understand why my project worked locally but when i deploy to kubernetes cluster it doesn't even start.

Thanks @corymsmith

corymsmith commented 1 year ago

I’m glad you managed to get it sorted because I spent a ton of time starting out what was going on.

On Thu, Jun 1, 2023 at 3:56 PM Umar Mash @.***> wrote:

Spent 3 days trying to understand why my project worked locally but when i deploy to kubernetes cluster it doesn't even start.

Thanks @corymsmith https://github.com/corymsmith

— Reply to this email directly, view it on GitHub https://github.com/stellar/js-stellar-sdk/issues/798#issuecomment-1572840340, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAABZE5KRB65OT3MKQL64BTXJEFYDANCNFSM6AAAAAARZ5WSQE . You are receiving this because you were mentioned.Message ID: @.***>

-- Thanks,

Cory

Shaptic commented 1 year ago

Thanks for bringing this thread out from the depths, guys, and documenting the solution @corymsmith :pray:

I imagine this is because sodium-native fails to compile, which you can (probably) work around by not installing optional dependencies (npm i --omit optional stellar-sdk).

gregemax commented 2 months ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

I have a solid background in JavaScript and TypeScript, with experience in developing and debugging applications using various Node.js environments. My familiarity with the Stellar SDK and my understanding of containerization using Docker make me well-equipped to analyze and resolve issues related to the Keypair fromSecret function in Alpine Linux. I’ve previously tackled segmentation faults in other libraries and am comfortable using debugging tools to identify and fix underlying problems.

How I plan on tackling this issue

Reproduce the Issue: Use the provided Docker command to replicate the segmentation fault.

Debug: Employ tools like gdb to gather stack traces and identify the root cause.

Analyze Dependencies: Check for compatibility issues with native modules in Alpine's musl libc.

Propose a Fix: Suggest code changes or document findings for the maintainers.

Test: Implement tests to ensure functionality across various Node.js environments.

Shaptic commented 1 month ago

@gregemax thanks for taking this on! Please make sure that you use the latest version of the library and alpine; it's entirely possible that this is no longer reproducible.

gregemax commented 1 month ago

hi @Shaptic Could you clarify the specific challenges you're facing with the Keypair.fromSecret function in stellar-sdk when running in Alpine Linux? Also, are there any recommended workarounds or solutions for this issue? Additionally, could you point me to the relevant file where I should look for integration details, and are there any important best practices or compatibility considerations with Alpine that I should be aware of before I start working with the SDK

Shaptic commented 1 month ago

I haven't tried to reproduce this bug - everything you need should be described in the issue description. There are multiple workarounds described above.

The relevant code is in signing.js, since there are two different crypto libraries you can use in the SDK. It sounds like this is only related to one of them.