bolt-python
bolt-python copied to clipboard
Slack bolt - How the slack bolt app behaves with multiple listeners
We have built a slack app using slack_bolt package. Our goal is when user asks question in slack, the slack app should respond. The slack app does respond but we are facing below mentioned issues:
- When the app is deployed on different environments, the message sent on slack randomly reaches any environment. Would like to understand the expected behavior of app with multiple listeners.
- We have observed more than 1 responses for the same question asked, the event is getting triggered for the same question.
- When the application is running for a long period of time, we have observed below error:
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))When the app throws this error, it does not respond.
Reproducible in:
The slack_bolt version
slack_bolt==1.23.0 slack_sdk==3.35.0
Python runtime version
Python 3.11.9
OS info
Red Hat Enterprise Linux 8.10
Steps to reproduce:
(Share the commands to run, source code, and project settings (e.g., setup.py))
This is simplified version of what we are trying to execute.
@app.message("")
def handle_any_message(message, say):
print("====Event received: ", message["text"] )
# respond to message events only from Trustbot DM, exclude all other channels. Respond only from local env
if message["channel"] == "E98NY8CUMSM" and os.getenv("NON_PROD",None) != "true": #respond only in given channel and particular environment
print("====LOCAL listener func called by DM========")
print("message text: ", message["text"])
user_text = message["text"]
channel_id = message["channel"]
blocks = call_assistant(assistant,user_text,session_id)
say(blocks = blocks,thread_ts=message["ts"])
Note: Currently the app is made to respond only in private DM, for development and testing purpose
Actual result:
- The application is running on 3 environments: test, pre-prod and prod. The slack app is added in one public channel and as standalone slack app.
- User sends a message on slack, the message is randomly catched by any one of the above mentioned environments. We have disabled the application from responding in pre-prod and test environments (using the NON_PROD environment variable).
Want to know answers to below questions:
- How does the application behave with multiple listeners?
- How can we resolve the "Remote Disconnected" error?
- If 2 applications are running at the same time, will we get conflicting responses?
Hello @ShreyaPimprikar,
Thank you for your questions, would you mind letting me know couples of things to help me understand the issue better?
- When you mention the app is running on 3 envs, are those 3 envs like different Slack workspaces?
- For the "Remote Disconnected" error, it could mean the bot token is invalid or revoked, so when the app might use the bot token to make request to the wrong environments
Hi @cchensh Thank you for your reply. Let me answer your queries:
- The app is running on 3 environments meaning the application code is deployed on 3 environments but it is connected to the same slack app installed in same workspace. For eg: the application code which has the listeners and logic to reply to the slack question is deployed on 3 environments. The application code is connected to same slack app.
- How do we know if the bot token is invalid or revoked? Also after few seconds after the error is thrown, the bot does respond to questions asked.
Hi @ShreyaPimprikar , thank you for the answers. I will chat with team and circle back to you soon.
Hello @ShreyaPimprikar , thank you for your patience: For question "How does app behave with multiple listeners", please find similar ticket here. TLDR: by design, socket mode randomizes sending the event between the socket connections
You can also take a look at the request headers to see if multiple responses are from reties or not. It would be helpful to know if the same app instance is returning multiple responses, or if it's returning multiple responses across different instances.
For the connection error, as you pointed out the app still works after couples of seconds, maybe this can help you with that?
Thank you for your response @cchensh . I will take a look at these resources and get back to you. Regarding the duplicate responses, I have tried to log the incoming message events and they do come from the same instance. What could be the reason behind this issue?
Hi @cchensh For the duplicate replies from slack, I think slack is internally retrying so the event gets triggered again. Could you please explain the reason behind why the retry happens?
👋 It looks like this issue has been open for 30 days with no activity. We'll mark this as stale for now, and wait 10 days for an update or for further comment before closing this issue out. If you think this issue needs to be prioritized, please comment to get the thread going again! Maintainers also review issues marked as stale on a regular basis and comment or adjust status if the issue needs to be reprioritized.
As this issue has been inactive for more than one month, we will be closing it. Thank you to all the participants! If you would like to raise a related issue, please create a new issue which includes your specific details and references this issue number.