aws-sdk-js-v3 icon indicating copy to clipboard operation
aws-sdk-js-v3 copied to clipboard

S3 Client Segmentation Fault on Ubuntu

Open jameswestbv opened this issue 3 years ago • 3 comments
trafficstars

Describe the bug

When using the S3 Client in a Node JS worker thread a seg fault occurs when exiting the thread when running on Ubuntu 20.04 (Example works as expected on Windows)

Your environment

NodeJs 16.14.0 Ubuntu 20.04.3 LTS

SDK version number

@aws-sdk/[email protected]

Is the issue in the browser/Node.js/ReactNative?

Node.js

Details of the browser/Node.js/ReactNative version

v16.14.0

Steps to reproduce

#!/usr/bin/env node

import { S3 } from '@aws-sdk/client-s3';
import { Worker, isMainThread, parentPort } from 'worker_threads';

if (isMainThread) {

	const worker = new Worker('./segfault.js');

	worker.on('message', (msg) => {
		console.log('Worker says: '+msg);
	});

	worker.on('exit', (code) => {
		console.log('Worker Thread exit');
	})

} else {
	
	// This code is executed in the worker and not in the main thread.

	async function doSomeWorkerWork() {
	
		let s3Client = new S3({
			endpoint: "https://ams3.digitaloceanspaces.com",
			region: "us-east-1",
			credentials: {
				accessKeyId: "doesn't matter for this test",
				secretAccessKey: "doesn't matter for this test"
			}
		});

		// Do something important with S3
		await new Promise(resolve => setTimeout(resolve, 1000));
		
		parentPort.postMessage('I\'m Done');
		
		s3Client.destroy();

		process.exit(0);

	}

	doSomeWorkerWork();

}

Observed behavior

When the thread exits it results in Segmentation Fault(core dumped)

Expected behavior

Thread should exit gracefully as it does on Windows

Screenshots

Ubuntu: ubuntu

Windows: windows

Additional context

Removing the instantiation of the S3 client makes the seg fault go away. The destroy() has no affect, tried it as it was recommended for node js

jameswestbv avatar Feb 16 '22 10:02 jameswestbv

I get the same error and exit code if I use the S3Client inside of a child_process.

Steffen911 avatar Feb 25 '22 11:02 Steffen911

I am facing the same issue with worker_threads.

The biggest problem is that the main process crashes when the worker thread exits (because of the segfault).

@vudh1 I see you unassigned yourself 8 days ago, would you have any update on this issue?

Coniface avatar Mar 23 '22 16:03 Coniface

I just ran into the same bug on Ubuntu 20.04.4 with @aws-sdk/[email protected] and node v16.14.2. Very eager to see this fixed.

AidanJHMurphy avatar Apr 07 '22 23:04 AidanJHMurphy

I'm facing a similar issue using S3Client in a worker thread using AWS Lambda with latest Node.js 18.x runtime. I'd say it fails on roughly half the invocations of the function.

I see this error in the logs:

Error: Runtime exited with error: signal: segmentation fault

jaw111 avatar Dec 02 '22 15:12 jaw111

Hi @jameswestbv, thanks for opening this issue. I tried to reproduce this issue but I could not. What I did was the following:

  • I installed node:
    • sudo apt update
    • sudo apt upgrade
    • If curl is not installed sudo apt install -y curl
    • curl -fsSL https://deb.nodesource.com/setup_19.x | sudo -E bash -
    • sudo apt install -y nodejs
  • The steps above will install the version 19.x of node, however, to install the version you mentioned in specific I did the following:
    • sudo npm cache clean -f
    • sudo npm install -g n
    • sudo n 16.14.0
  • Then, I created a node project as follow:
    • npm init
    • create a js file. Example: src/index.js
    • Install the used dependencies: npm i @aws-sdk/client-s3
    • Copy and paste the code below:
    #!/usr/bin/env node
    
    import {
        Worker, isMainThread, parentPort
    } from "worker_threads";
    import {ListBucketsCommand, S3Client} from "@aws-sdk/client-s3";
    
    if (isMainThread) {
        const worker = new Worker('./index.js');
        worker.on('message', (msg) => {
            console.log('Worker message: ', msg)
        })
    
        worker.on('exit', (code) => {
            console.log('Exit because: ', code)
        })
    
        worker.on('error', (error) => {
            console.log('Error: ', error)
        })
    } else {
        const doWork = async () => {
            const client = new S3Client({
                region: 'us-east-2',
                credentials: {
                    accessKeyId: 'accesskeyId',
                    secretAccessKey: 'secretAccessKey'
                }
            })
            const response = await client.send(new ListBucketsCommand({}));
            console.log(response)
            parentPort.postMessage('I am done!')
            client.destroy()
            process.exit(0)
        }
    
        await doWork();
    }
    

So, is there any other detail I should consider to reproduce the error?

@Steffen911, @Coniface, @AidanJHMurphy, and @jaw111, would it be possible for any of you to provide reproduction steps based on your implementation?

Thanks!

yenfryherrerafeliz avatar Jan 17 '23 04:01 yenfryherrerafeliz

Could you people also confirm if you have two installations of node?, you could confirm that by running nodejs -v and node -v and check if for both commands you get a result?

Thanks!

yenfryherrerafeliz avatar Jan 17 '23 04:01 yenfryherrerafeliz

@yenfryherrerafeliz

Looks like it has been fixed at some point in the last year between version 3.46.0 --> 3.252.0

If you really want to reproduce it you would need the latest version from Feb 2022 when I raised this which is npm i @aws-sdk/[email protected]

But as it looks like its fixed in the later versions then there isn't much more to add.

jameswestbv avatar Jan 18 '23 11:01 jameswestbv

@yenfryherrerafeliz I'm using the Node.js 18.x runtime for AWS Lambda. If it is useful/necessary to reproduce the bug in Lambda, I could provide some minimal code that demonstrates the issue, but it would also require the necessary AWS infrastructure to run it. Do you have any suggestions how to go about that?

jaw111 avatar Jan 18 '23 13:01 jaw111

Hi @jaw111, thanks for replying back. Would it be possible for you to check if with the latest version the issue persist?

Thanks!

yenfryherrerafeliz avatar Jan 19 '23 19:01 yenfryherrerafeliz

This issue has not received a response in 1 week. If you still think there is a problem, please leave a comment to avoid the issue from automatically closing.

github-actions[bot] avatar Jan 27 '23 00:01 github-actions[bot]

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

github-actions[bot] avatar Feb 14 '23 00:02 github-actions[bot]