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
Throwing error in fetchInstallation leads to "An incoming event was not acknowledged within 3 seconds" error and Lambda timeout #859
Comments
@broom9 Thanks for taking the time to report this! The issueAs you mentioned, in this scenario, a Bolt app outputs the following log messages and returns 500 Internal Server Error. There is no way to customize the behavior as long as you use any of the built-in receivers. I agree there is room for improvement regarding this.
The following is a simple OAuth example app I used for verifying this issue: const { LogLevel } = require("@slack/logger");
const { App } = require("@slack/bolt");
const database = {};
const app = new App({
logLevel: process.env.SLACK_LOG_LEVEL || LogLevel.DEBUG,
signingSecret: process.env.SLACK_SIGNING_SECRET,
clientId: process.env.SLACK_CLIENT_ID,
clientSecret: process.env.SLACK_CLIENT_SECRET,
stateSecret: 'my-state-secret',
scopes: ['commands', 'chat:write'],
installationStore: {
storeInstallation: async (installation) => {
// change the line below so it saves to your database
if (installation.isEnterpriseInstall) {
// support for org wide app installation
database[installation.enterprise.id] = installation;
} else {
// single team app installation
database[installation.team.id] = installation;
}
},
fetchInstallation: async (installQuery) => {
// change the line below so it fetches from your database
if (installQuery.isEnterpriseInstall && installQuery.enterpriseId !== undefined) {
// org wide app installation lookup
return database[installQuery.enterpriseId];
}
if (installQuery.teamId !== undefined) {
// single team app installation lookup
return database[installQuery.teamId];
}
throw new Error('Failed fetching installation');
},
},
});
(async () => {
await app.start(process.env.PORT || 3000);
console.log("⚡️ Bolt app is running!");
})(); Possible solution for this issueTo improve this, there are several approach we can consider. We can do all of them at the same time if necessary. To eliminate the issue described here, I think we can work on 1: first. And then, we may consider implementing 2: separately when we have the bandwidth for it.
1: Change the built-in receivers' default behavior (return 40x status, not 500 - skip the "no ack" error message)We can improve all the built-in receivers that have this issue. In the case of
I assume no existing apps expect 500 response status in this scenario. If there is a strong concern on it, we may move the change to v4 milestone and also provide some fallback option. With being that said, I'm thinking it's safe enough to "improve" the behavior in a minor release for the reason I mentioned above (the bold part). 2: Enable developers to set a custom error handler in the built-in receiverDevelopers can customize the global error handler on the If developers would like to customize the behavior in the scenario of this issue, they have to implement their own custom receiver. If it's possible to customize only the error handling part by passing a function in the constructor, it would be far better for maintainability of the code. The possible use case would be: We may want to have a new task issue for this enhancement. Thoughts? I would like to know other maintainers' thoughts on this before starting working on 1: task. |
I will implement the solution 1 in the v3.4.0 release. For the solution 2, I will create another issue for it. We may work on it in the future versions. |
👋 I just started working on this task at #891 - let us know if you have feedback or suggestions on it |
As we are aiming to release v3.4.0 within a few days and this pull request needs more time, let me move this one to v3.5 milestone. |
Description
Hi there,
We have some use cases that we need to throw errors in the
fetchInstallation
method in the OAuth flow (Slack teams that are not recognized by us installed our Slack app).Based on the document https://slack.dev/bolt-js/concepts#error-handling. Throwing an error in the
fetchInstallation
is the way to handle errors.But when an error is thrown in the
fetchInstallation
method, after 3 seconds, an error log "[ERROR] An incoming event was not acknowledged within 3 seconds. Ensure that the ack() argument is called in a listener." will be printed.And using Lambda serverless deployment, the Lambda will timeout and be considered as failed to execute.
I think there might be some error handling issue with errors thrown from
fetchInstallation
. The 3 seconds error message shouldn't show, and Lambda shouldn't timeout or fail in this case.What type of issue is this? (place an
x
in one of the[ ]
)Requirements (place an
x
in each of the[ ]
)Bug Report
Filling out the following details about bugs will help us solve your issue sooner.
Reproducible in:
package version: 3.3.0
node version: 12.18.4
OS version(s): Linux
Steps to reproduce:
Expected result:
A 401 or 403 response is returned on authorization error.
Lambda doesn't timeout or fail.
Actual result:
No response was returned.
Lambda timeout
Attachments:
Logs, screenshots, screencast, sample project, funny gif, etc.
The text was updated successfully, but these errors were encountered: