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

How to enable multiple connection in socket mode in bolt python #1071

Open
PrajwalNaik07 opened this issue Apr 22, 2024 · 5 comments
Open

How to enable multiple connection in socket mode in bolt python #1071

PrajwalNaik07 opened this issue Apr 22, 2024 · 5 comments
Labels
question Further information is requested

Comments

@PrajwalNaik07
Copy link

I read in the slack documentation that Socket Mode allows your app to maintain up to 10 open WebSocket connections at the same time.

I am unable to find code example for it, please help

@WilliamBergamin WilliamBergamin added the question Further information is requested label Apr 22, 2024
@WilliamBergamin
Copy link
Contributor

Hi @PrajwalNaik07 thank fro writing in

You should be able to accomplish this by starting multiple python processes that execute your application source code
For example run python app.py in 2 separate terminals each process will open a WebSocket connections.

@PrajwalNaik07
Copy link
Author

Hi @WilliamBergamin ,

I tried the above approach, and it significantly reduces my issues, but in one instance saw that a particular event was triggered in one of the replica pods but the socket mode got reconnected in between the process execution resulting in failure of the process, could you tell me how to avoid this even thought I am running multiple pods for my app

@seratch
Copy link
Member

seratch commented Apr 30, 2024

As long as you keep at least one connection alive all the time, terminating others does not matter. Slack's API server delivers to any of the active connections and does retries for Events API messages. If you terminate all the instances at a time, indeed the situation your app may miss some events may arise.

@PrajwalNaik07
Copy link
Author

Hi @seratch ,

So we are running two pods for the app socket mode, and they are handling all the requests but in my case I have added a button in the app and when the user clicks the button I start a particular function. I have logged when the process starts, and when checked the pods it seems like the process started but before completion of the process the socket mode got reconnected loosing to complete the function, so according the socket mode the request was received but before completion the socket mode got re-established resulting in failure of process and giving the fallback output. How do I handle this

@seratch
Copy link
Member

seratch commented Apr 30, 2024

I appreciate your clarification on the matter.

Indeed, with Socket Mode, there could be a risk of the event handling failure like you described. Unfortunately, there's no perfect solution to completely avoid this potential issue with Socket Mode. The connection can be re-establihed upon a request from Slack server or due to a network error.

If clicking the button again isn't acceptable for your app's operational need, an alternative approach would be to run your Slack app instances behind a publicly accesible "Request URL" instead, plus to implement a graceful shutdown process for running bolt-python instances. This will help prevent the loss of any events being processed.

I understand this could be frustrating for your need, but I hope this was helpful to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants