bolt-js: processBeforeRepsonse: true doesn't work when a Bolt listener function has WebClient calls inside
Description
When deploying a Bolt app to AWS Lambda, and using processBeforeResponse
option, the listener is not able to complete before the HTTP response is finished.
This issue was reported by a user in the Slack Community workspace: https://community.slack.com/archives/CHY642221/p1585670255001600.
Requirements (place an x
in each of the [ ]
)
- I’ve read and understood the Contributing guidelines and have done my best effort to follow them.
- I’ve read and agree to the Code of Conduct.
- I’ve searched for any related issues and avoided creating a duplicate issue.
Bug Report
Filling out the following details about bugs will help us solve your issue sooner.
Reproducible in:
package version: 2.0.0
node version: NA
OS version(s): NA
Steps to reproduce:
-
Use the following code:
const { App, ExpressReceiver } = require('@slack/bolt'); const expressReceiver = new ExpressReceiver({ signingSecret: process.env.SLACK_SIGNING_SECRET }); const app = new App({ token: process.env.SLACK_BOT_TOKEN, receiver: expressReceiver, processBeforeResponse: true }); // ------------------------ // Application Logic // ------------------------ app.event('app_home_opened', async ({ context, event, say }) => { console.log(`event: ${JSON.stringify(event)}`); await say(`Hello world, and welcome <@${event.user}> from AWS Lambda.`); console.log("finish to say"); });
-
Deploy to AWS Lambda
-
Open the App Home in Slack to trigger the event subscription.
Expected result:
User should receive the message sent using say()
, and the logs should show “finish to say”.
Actual result:
There’s no message and the line does not appear in the logs.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 16 (16 by maintainers)
Thanks for working on this and I’m happy to know you’ve figured out the cause! The above explanation is very clear and that makes sense a lot to me.
I haven’t verified if applying the fix on conversation store fixes the issue yet. If you need someone to double-check, I can do that. But if you’re already confident enough, let’s ship the fix as soon as possible.
As I shared above, the main issue we’re still tackling is that
processBeforeRepsonse: true
doesn’t work when a Bolt listener function hasWebClient
calls inside.HTTP requests by axios always run separately from an async listener/middleware function. I’m still not sure if there is a way to take control from the Bolt framework side (even not sure if it’s specific to axios or it can happen with other 3rd parties yet).
In my understanding, there are three options here:
axios
HTTP requests run as part of Bolt’s async functionssetTimeout
internallyack()
manually in Events API listeners (the approach I originally proposed at #395 ) and removeprocessBeforeResponse
@aoberoi @stevengill @shaydewael I’d like to know your thoughts on this.
I prefer 0️⃣ > 2️⃣ > 1️⃣ but I can agree with any decision. For 0️⃣, I don’t have the bandwidth to take it this week, so that I would like someone else (any contributions from the community are of course welcome!) to do a deep dive.
My intention of putting v2.0 milestone is marking the changes that will be included 2.0 patch releases but it may be a bit irregular way of the milestone’s usage. I agree that we can close it as we’ve already released the initial version of the series.