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

Creating multiple signed URL promises fails with duplicate middleware error #1857

Closed
olokobayusuf opened this issue Jan 2, 2021 · 7 comments · Fixed by #1884
Closed

Creating multiple signed URL promises fails with duplicate middleware error #1857

olokobayusuf opened this issue Jan 2, 2021 · 7 comments · Fixed by #1884
Labels
bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@olokobayusuf
Copy link

olokobayusuf commented Jan 2, 2021

I'm using the @aws-sdk/client-s3 and @aws-sdk/s3-request-presigner packages to sign S3 object URL's in my GraphQL API. I've run into an issue where if there are multiple promises requesting a URL in one node tick, the following error occurs:

Duplicated middleware name 'presignInterceptMiddleware'

Doing some quick digging through the s3-request-presigner code, it looks like the implementation uses a naive stack placement without regard for multiple concurrent requests being a possibility:

client.middlewareStack.addRelativeTo(presignInterceptMiddleware, {
name: "presignInterceptMiddleware",
relation: "before",
toMiddleware: "awsAuthMiddleware",
});
let presigned: HttpRequest;
try {
const output = await client.send(command);
//@ts-ignore the output is faked, so it's not actually OutputType
presigned = output.presigned;
} finally {
client.middlewareStack.remove("presignInterceptMiddleware");
}

As such, the following code will fail:

const getObjectCommands = [...];
await Promise.all(getObjectCommands.map(command => getSignedUrl(s3, command));

Whereas this won't:

const getObjectCommands = [...];
for (const command of getObjectCommands)
    await getSignedUrl(s3, command);

I was able to partially workaround this by refactoring my code, but now I happen to be exposing URL pre-signing through a resolver managed by GraphQL. As such I can't refactor the code to avoid this bug; it can only be fixed upstream. I remember that a while ago, pre-signed URL's didn't need to make any actual request; it was entirely generated locally. Can this behaviour be imitated? And how quickly can this bug be fixed? It's a (very serious) blocker.

SDK version number

"@aws-sdk/client-s3": "^3.1.0",
"@aws-sdk/s3-request-presigner": "^3.1.0",
"@aws-sdk/types": "^3.1.0",

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

Details of the browser/Node.js/ReactNative version
Node JS v12.4.0

To Reproduce (observed behavior)
See above.

Expected behavior
No middleware stack error should occur.

Screenshots
From GraphQL:

"errors": [
    {
      "message": "Duplicated middleware name 'presignInterceptMiddleware'",
      "locations": [
        {
          "line": 9,
          "column": 9
        }
      ],
      "path": [...],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR"
      }
    }
]

Additional context
Add any other context about the problem here.

@steventhanna
Copy link

Can confirm I am experiencing similar behavior when implemented in a REST API.

@steventhanna
Copy link

As a temporary work around until there is a patch, I switched to: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#getSignedUrlPromise-property

let promise = s3.getSignedUrlPromise('getObject', params)

which has been working so far without incident.

@olokobayusuf
Copy link
Author

As a temporary work around until there is a patch, I switched to: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#getSignedUrlPromise-property

let promise = s3.getSignedUrlPromise('getObject', params)

which has been working so far without incident.

What package and version are you using? In @aws-sdk/client-s3, the S3 class no longer contains the getSignedUrlPromise method.

@steventhanna
Copy link

@olokobayusuf I'm using the latest version of aws-sdk (2.824.0) which you can find here

@olokobayusuf
Copy link
Author

@olokobayusuf I'm using the latest version of aws-sdk (2.824.0) which you can find here

Thanks! I realized you probably weren't using the v3 SDK any longer. @AllanZhengYP I see you've moved this to In progress. Do you have an ETA?

@steventhanna
Copy link

Thanks @AllanZhengYP!!

@github-actions
Copy link

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 github-actions bot locked as resolved and limited conversation to collaborators Jan 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants