Skip to content

Unhandled 'error' event caused by ChecksumStream #6845

@agaevaslan

Description

@agaevaslan

Checkboxes for prior research

Describe the bug

                const inputData = {
			Bucket: bucketName,
			Key: fileKey,
			Range: _range
		}

		try {
			const getObjectCommand = new GetObjectCommand(inputData)
                         const s3Client = new S3Client({
			    region,
			    credentials,
		         })
			const response = await s3Client.send(getObjectCommand)
                } catch (e) {
                         console.log(e)
                }

when getting a filestream from s3 with GetObjectCommand, if there's a checksum mismatch in @aws-sdk/middleware-flexible-checksums/node_modules/@smithy/util-stream/dist-cjs/checksum/ChecksumStream.js the error is thrown:

`Checksum mismatch: expected "${this.expectedChecksum}" but received "${received}"` +
                    ` in response header "${this.checksumSourceLocation}".`

this error causes from Unhandled 'error' event in ChecksumStream.

It's not catched in catch block around s3Client.send(getObjectCommand) (since it happens after receiving the result after the response stream (response.Body starts producing data) and causes an unhandled exception.
There seems to be no way to catch/handle it (except using global unhandled expection handlers).

Regression Issue

  • Select this option if this issue appears to be a regression.

SDK version number

@aws-sdk/client-s3 v3.732.0

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

v20.18.1

Reproduction Steps

                const inputData = {
			Bucket: this._config.bucketName,
			Key: fileKey,
			Range: _range
		}

		try {
			const getObjectCommand = new GetObjectCommand(inputData)
                         const s3Client = new S3Client({
			    region,
			    credentials,
		         })
			const response = await s3Client.send(getObjectCommand)
                } catch (e) {
                         console.log(e)
                }

in order to simulate checksum mismatch you can change this.expectedChecksum !== received to this.expectedChecksum === received or smth trueish in @aws-sdk/middleware-flexible-checksums/node_modules/@smithy/util-stream/dist-cjs/checksum/ChecksumStream.js.

Observed Behavior

Checksum mismatch error causes unhandled error event

Expected Behavior

Checksum mismatch error should not cause unhandled error event

Possible Solution

Expose ChecksumStream outside to allow setting error handlers

Additional Information/Context

No response

Metadata

Metadata

Assignees

Labels

bugThis issue is a bug.closing-soonThis issue will automatically close in 4 days unless further comments are made.p1This is a high priority issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions