Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problems about node http when used with the aws sdk. #115

Open
myuoong opened this issue Jun 8, 2022 · 1 comment
Open

problems about node http when used with the aws sdk. #115

myuoong opened this issue Jun 8, 2022 · 1 comment
Labels
bug Something isn't working question Further information is requested
Milestone

Comments

@myuoong
Copy link

myuoong commented Jun 8, 2022

hi
i got this error when used with aws sdk

ERR_HTTP_HEADERS_SENT","$metadata":{"attempts":1,"totalRetryDelay":0}}]message: Cannot set headers after they are sent to the client

i think the agent try to set header after http send to client

here i tried test code:

import 'pinpoint-node-agent';
import * as fs from 'fs';
import express from 'express';
import { S3Client, PutObjectCommand, CreateBucketCommand } from "@aws-sdk/client-s3";

// Set the AWS Region.
const REGION = "ap-northeast-2"; //e.g. "us-east-1"
// Create an Amazon S3 service client object.
const s3Client = new S3Client({ region: REGION });

const file = await fs.readFileSync(`./test.pdf`);

// Set the parameters
const params = {
    Bucket: "", // The name of the bucket. For example, 'sample_bucket_101'.
    Key: "", // The name of the object. For example, 'sample_upload.txt'.
    Body: Buffer.from(file), // The content of the object. For example, 'Hello world!".
    ContentType: 'application/pdf',
    ACL: 'private',
};

const run = async () => {
    // Create an object and upload it to the Amazon S3 bucket.
    for (let i=0; i<10; i++) {
        try {
            const results = await s3Client.send(new PutObjectCommand({...params, Key: `path/file-name${i}.pdf`}));
            console.log(
                "Successfully created " +
                params.Key +
                " and uploaded it to " +
                params.Bucket +
                "/" +
                params.Key +
                "\nresults:" + JSON.stringify(results)
            );
        } catch (err) {
            console.log("Error"+i, err);
        }
    }
};

const app = express()
const port = 3000

app.get('/', (req, res) => {
    run().then( () => {
        res.send('Hello World!')
    }).catch(e => {
        res.send(e)
    });
})

app.listen(port, () => {
    console.log(`Example app listening on port ${port}`)
})
//package.json
{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@aws-sdk/client-s3": "^3.105.0",
    "express": "^4.18.1",
    "pinpoint-node-agent": "^0.8.3"
  },
  "type": "module"
}
PINPOINT_APPLICATION_NAME=TEST PINPOINT_AGENT_ID=TEST_AGENT node index.js

curl localhost:3000

Error9 Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at new NodeError (node:internal/errors:371:5)
    at ClientRequest.setHeader (node:_http_outgoing:576:11)
    at Function.setHeader (/home/node/app/test/node_modules/pinpoint-node-agent/lib/instrumentation/request-header-utils.js:93:15)
    at Function.write (/home/node/app/test/node_modules/pinpoint-node-agent/lib/instrumentation/request-header-utils.js:79:12)
    at /home/node/app/test/node_modules/pinpoint-node-agent/lib/instrumentation/http-shared.js:119:26
    at /home/node/app/test/node_modules/@aws-sdk/node-http-handler/dist-cjs/node-http-handler.js:70:25
    at new Promise (<anonymous>)
    at NodeHttpHandler.handle (/home/node/app/test/node_modules/@aws-sdk/node-http-handler/dist-cjs/node-http-handler.js:49:16)
    at /home/node/app/test/node_modules/@aws-sdk/client-s3/dist-cjs/commands/PutObjectCommand.js:39:58
    at /home/node/app/test/node_modules/@aws-sdk/middleware-serde/dist-cjs/deserializerMiddleware.js:5:32 {
  code: 'ERR_HTTP_HEADERS_SENT',
  '$metadata': { attempts: 1, totalRetryDelay: 0 }
}
@feelform feelform added the bug Something isn't working label Jun 16, 2022
@feelform feelform modified the milestones: 0.10.0, 0.9.0 Jun 16, 2022
@feelform
Copy link
Collaborator

Hello, myuoong

Thank you for your reports. It's a Pinpoint Node agent issue.

@feelform feelform added the question Further information is requested label May 2, 2024
@feelform feelform modified the milestones: 0.9.0, 1.0.0 May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants