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

Possible race condition: back-to-back replies when deployed in production #27

Open
abhinavsharma opened this issue Apr 5, 2023 · 3 comments
Labels
bug Something isn't working help wanted Extra attention is needed question Further information is requested

Comments

@abhinavsharma
Copy link

abhinavsharma commented Apr 5, 2023

I've noticed that running on dev never has this problem but main_prod.py on lambda might.

The way it's designed, the reply listener triggers for first time messages as well but should early terminate — https://github.com/seratch/ChatGPT-in-Slack/blob/main/app/bolt_listeners.py#L311

But something about the way it's deployed to prod seems to be causing multiple replies sometimes

@seratch seratch added bug Something isn't working help wanted Extra attention is needed labels Apr 5, 2023
@seratch
Copy link
Owner

seratch commented Apr 5, 2023

Hi @abhinavsharma, thanks for reporting this! Quick question: Are you using main_prod.py as-is or have you customized some parts of that? Especially I am curious if you're using secure parameter store and/or any additional AWS services unlike the original version's simplicity (=accessing env variables) The most possible cause of this situation would be 3 second timeout for the ack function (and those modules tend to cause cold-start issues for Lambda functions more often). In the scenario, your app's reply to an app_mention event can be repeated (in other words, Slack retries the same event delivery as your app didn't respond within 3 seconds). The message event listener skips all the message events without thread_ts inside the code. So, I don't think it can be the cause.

@seratch seratch added the question Further information is requested label Apr 5, 2023
@budbach
Copy link
Contributor

budbach commented Sep 27, 2023

Don't know what is causing this but I've been noticing it too.

It might be related to timeouts. I'm deploying with serverless and the AWS gateway times out after 30 seconds and I have OPENAI_TIMEOUT_SECONDS set to 30 seconds app has a timeout of 29 seconds.

Maybe OPENAI_TIMEOUT_SECONDS needs to be less than the app timeout.

@paonets
Copy link

paonets commented May 26, 2024

I noticed this too when running the bot from AWS Lambda. It seems that the Lambda cold start took too long, so it couldn't respond within 3 seconds. As a result, Slack resent the event. You can notice this in the x-slack-retry-num value in the event.

To fix this, I tried increasing the memory size of Lambda to 2048 MB so it's a bit faster. This seems to help. Another possible solution is to ignore the event with x-slack-retry-num >= 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants