-
Notifications
You must be signed in to change notification settings - Fork 833
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
Django connection issue with RTM v2 client #1238
Comments
Hi @pbrackin, thanks for sharing this. The connection releasing logic may not work in the case where your message listener receives a message from its bot user itself: https://github.com/slackapi/python-slack-sdk/blob/v3.17.2/slack_sdk/rtm_v2/__init__.py#L162-L164 We are happy to add some customization points for this use case but, can you verify whether the approach works for you?
def process_message(self):
release_thread_local_connections() # ADDED
try:
raw_message = self.message_queue.get(timeout=1)
if self.logger.level <= logging.DEBUG:
self.logger.debug(f"A message dequeued (current queue size: {self.message_queue.qsize()})")
if raw_message is not None:
message: dict = {}
if raw_message.startswith("{"):
message = json.loads(raw_message)
def _run_message_listeners():
self.run_message_listeners(message)
self.message_workers.submit(_run_message_listeners)
except Empty:
pass
finally: # ADDED
release_thread_local_connections() # ADDED If this works well, we will add two callbacks like |
Thanks @seratch for following up on this. Sorry I didn't get to respond a little sooner. I will run this experiment when I get some time. But I wanted to also point out that I found a solution that seems to work ok. What I did was call |
@pbrackin Thanks for your reply. Most of the things you mentioned should be good ways to go but
This should be Let me know if my above suggestions work for you. Once it is effective, we are happy to enhance the RTM v2 client to enable developers to pass callback functions for this use case. |
We are refitting to use the v2 RTM client and still observe some stale Django connection issues. Ie, new DB connections are made for each message that gets processed (thread), but they are apparently not being released. I have tried using the close_old_connections & also ensure_connection, but seems like it doesn't really help. I saw you did the changes for the slack-bolt thing here. Were there going to be similar changes to the v2 RTM client? Do you have any recommendations in the interim?
Originally posted by @pbrackin in slackapi/bolt-python#280 (comment)
The text was updated successfully, but these errors were encountered: