alan-turing-institute / reginald

Reginald repository for REG Hack Week 23
3 stars 0 forks source link

Ensure slackbot doesn't crash when multiple messages are sent at the same time by different users #94

Closed rwood-97 closed 11 months ago

rwood-97 commented 12 months ago

At the moment, the queuing works for single user so that they slackbot doesn't crash but when two different users message at the same time we get an error and it crashes.

rwood-97 commented 12 months ago

This is maybe fixed now by #93

rwood-97 commented 11 months ago

Seems okay though we get some errors in the logs:

2023-09-27 16:06:35 [   DEBUG] Received message (type: TEXT, data: {"envelope_id":"25f8c8b5-497d-46ee-924c-690a110e7ae9","payload":{"token":"OEqSunrvpkP80Su25M5fdu4W","team_id":"T057SAAS0K0","api_app_id":"A05RS0R47SA","event":{"client_msg_id":"d702f10a-7661-457b-8c3f-92e6a4964759","type":"app_mention","text":"<@U05RJ4R1V1D> what?","user":"U05BM5KRRK9","ts":"1695827194.721599","blocks":[{"type":"rich_text","block_id":"xLYe","elements":[{"type":"rich_text_section","elements":[{"type":"user","user_id":"U05RJ4R1V1D"},{"type":"text","text":" what?"}]}]}],"team":"T057SAAS0K0","channel":"C05T2SU35FX","event_ts":"1695827194.721599"},"type":"event_callback","event_id":"Ev05U8B02J3E","event_time":1695827194,"authorizations":[{"enterprise_id":null,"team_id":"T057SAAS0K0","user_id":"U05RJ4R1V1D","is_bot":true,"is_enterprise_install":false}],"is_ext_shared_channel":false,"event_context":"4-eyJldCI6ImFwcF9tZW50aW9uIiwidGlkIjoiVDA1N1NBQVMwSzAiLCJhaWQiOiJBMDVSUzBSNDdTQSIsImNpZCI6IkMwNVQyU1UzNUZYIn0"},"type":"events_api","accepts_response_payload":false,"retry_attempt":0,"retry_reason":""}, extra: , session: s_393286281)
2023-09-27 16:06:35 [   DEBUG] A new message enqueued (current queue size: 1, session: s_393286281)
2023-09-27 16:06:35 [   DEBUG] Message processing started (type: events_api, envelope_id: 25f8c8b5-497d-46ee-924c-690a110e7ae9, session: s_393286281)
2023-09-27 16:06:35 [    INFO] Received an events_api request
2023-09-27 16:06:35 [   DEBUG] Sending a message: {"envelope_id": "25f8c8b5-497d-46ee-924c-690a110e7ae9"} from session: s_393286281
2023-09-27 16:06:35 [   DEBUG] Event: {'client_msg_id': 'd702f10a-7661-457b-8c3f-92e6a4964759', 'type': 'app_mention', 'text': '<@U05RJ4R1V1D> what?', 'user': 'U05BM5KRRK9', 'ts': '1695827194.721599', 'blocks': [{'type': 'rich_text', 'block_id': 'xLYe', 'elements': [{'type': 'rich_text_section', 'elements': [{'type': 'user', 'user_id': 'U05RJ4R1V1D'}, {'type': 'text', 'text': ' what?'}]}]}], 'team': 'T057SAAS0K0', 'channel': 'C05T2SU35FX', 'event_ts': '1695827194.721599'}
2023-09-27 16:06:35 [    INFO] Reacting with clock emoji.
2023-09-27 16:06:35 [   DEBUG] Sending a request - url: POST https://www.slack.com/api/reactions.add, params: {'channel': 'C05T2SU35FX', 'name': 'clock2', 'timestamp': '1695827194.721599'}, files: {}, data: {}, json: {}, proxy: {}, headers: {'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': '(redacted)', 'User-Agent': 'Python/3.11.4 slackclient/3.22.0 Darwin/21.6.0'}
2023-09-27 16:06:35 [   DEBUG] Received message (type: TEXT, data: {"envelope_id":"5f223574-c02c-4e08-81ae-474945a4377b","payload":{"token":"OEqSunrvpkP80Su25M5fdu4W","team_id":"T057SAAS0K0","context_team_id":"T057SAAS0K0","context_enterprise_id":null,"api_app_id":"A05RS0R47SA","event":{"client_msg_id":"d702f10a-7661-457b-8c3f-92e6a4964759","type":"message","text":"<@U05RJ4R1V1D> what?","user":"U05BM5KRRK9","ts":"1695827194.721599","blocks":[{"type":"rich_text","block_id":"xLYe","elements":[{"type":"rich_text_section","elements":[{"type":"user","user_id":"U05RJ4R1V1D"},{"type":"text","text":" what?"}]}]}],"team":"T057SAAS0K0","channel":"C05T2SU35FX","event_ts":"1695827194.721599","channel_type":"channel"},"type":"event_callback","event_id":"Ev05TZ89JU1L","event_time":1695827194,"authorizations":[{"enterprise_id":null,"team_id":"T057SAAS0K0","user_id":"U05RJ4R1V1D","is_bot":true,"is_enterprise_install":false}],"is_ext_shared_channel":false,"event_context":"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU3U0FBUzBLMCIsImFpZCI6IkEwNVJTMFI0N1NBIiwiY2lkIjoiQzA1VDJTVTM1RlgifQ"},"type":"events_api","accepts_response_payload":false,"retry_attempt":0,"retry_reason":""}, extra: , session: s_393286281)
2023-09-27 16:06:35 [   DEBUG] A new message enqueued (current queue size: 1, session: s_393286281)
2023-09-27 16:06:35 [   DEBUG] Message processing started (type: events_api, envelope_id: 5f223574-c02c-4e08-81ae-474945a4377b, session: s_393286281)
2023-09-27 16:06:35 [    INFO] Received an events_api request
2023-09-27 16:06:35 [   DEBUG] Response: <slack_sdk.socket_mode.response.SocketModeResponse object at 0x43fed2010>
2023-09-27 16:06:35 [   DEBUG] Sending a message: {"envelope_id": "5f223574-c02c-4e08-81ae-474945a4377b"} from session: s_393286281
2023-09-27 16:06:35 [   DEBUG] Event: {'client_msg_id': 'd702f10a-7661-457b-8c3f-92e6a4964759', 'type': 'message', 'text': '<@U05RJ4R1V1D> what?', 'user': 'U05BM5KRRK9', 'ts': '1695827194.721599', 'blocks': [{'type': 'rich_text', 'block_id': 'xLYe', 'elements': [{'type': 'rich_text_section', 'elements': [{'type': 'user', 'user_id': 'U05RJ4R1V1D'}, {'type': 'text', 'text': ' what?'}]}]}], 'team': 'T057SAAS0K0', 'channel': 'C05T2SU35FX', 'event_ts': '1695827194.721599', 'channel_type': 'channel'}
2023-09-27 16:06:35 [    INFO] Reacting with clock emoji.
2023-09-27 16:06:35 [   DEBUG] Sending a request - url: POST https://www.slack.com/api/reactions.add, params: {'channel': 'C05T2SU35FX', 'name': 'clock2', 'timestamp': '1695827194.721599'}, files: {}, data: {}, json: {}, proxy: {}, headers: {'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': '(redacted)', 'User-Agent': 'Python/3.11.4 slackclient/3.22.0 Darwin/21.6.0'}
2023-09-27 16:06:35 [   DEBUG] Received the following response - status: 200, headers: {'Date': 'Wed, 27 Sep 2023 15:06:35 GMT', 'Server': 'Apache', 'Vary': 'Accept-Encoding', 'x-slack-req-id': '70c333f3920576eb615e2861de95464e', 'x-content-type-options': 'nosniff', 'x-xss-protection': '0', 'Pragma': 'no-cache', 'Cache-Control': 'private, no-cache, no-store, must-revalidate', 'Expires': 'Sat, 26 Jul 1997 05:00:00 GMT', 'Content-Type': 'application/json; charset=utf-8', 'x-accepted-oauth-scopes': 'reactions:write', 'x-oauth-scopes': 'commands,im:history,reactions:write,chat:write,im:write,emoji:read,reactions:read,app_mentions:read,im:read,incoming-webhook,channels:history,chat:write.public,users.profile:read', 'Access-Control-Expose-Headers': 'x-slack-req-id, retry-after', 'Access-Control-Allow-Headers': 'slack-route, x-slack-version-ts, x-b3-traceid, x-b3-spanid, x-b3-parentspanid, x-b3-sampled, x-b3-flags', 'strict-transport-security': 'max-age=31536000; includeSubDomains; preload', 'x-slack-unique-id': 'ZRRE-6cNCK7gHv_JBduJCAAAABM', 'x-slack-backend': 'r', 'referrer-policy': 'no-referrer', 'Access-Control-Allow-Origin': '*', 'Content-Length': '38', 'Via': '1.1 slack-prod.tinyspeck.com, envoy-www-iad-eptiywew, envoy-edge-lhr-milphoza', 'x-envoy-attempt-count': '1', 'x-envoy-upstream-service-time': '107', 'x-backend': 'main_normal main_canary_with_overflow main_control_with_overflow', 'x-server': 'slack-www-hhvm-main-iad-pxjy', 'x-slack-shared-secret-outcome': 'no-match', 'x-edge-backend': 'envoy-www', 'x-slack-edge-shared-secret-outcome': 'no-match'}, body: {'ok': False, 'error': 'already_reacted'}
2023-09-27 16:06:35 [   ERROR] Something went wrong in processing a Slack request.
Payload: {'token': 'OEqSunrvpkP80Su25M5fdu4W', 'team_id': 'T057SAAS0K0', 'context_team_id': 'T057SAAS0K0', 'context_enterprise_id': None, 'api_app_id': 'A05RS0R47SA', 'event': {'client_msg_id': 'd702f10a-7661-457b-8c3f-92e6a4964759', 'type': 'message', 'text': '<@U05RJ4R1V1D> what?', 'user': 'U05BM5KRRK9', 'ts': '1695827194.721599', 'blocks': [{'type': 'rich_text', 'block_id': 'xLYe', 'elements': [{'type': 'rich_text_section', 'elements': [{'type': 'user', 'user_id': 'U05RJ4R1V1D'}, {'type': 'text', 'text': ' what?'}]}]}], 'team': 'T057SAAS0K0', 'channel': 'C05T2SU35FX', 'event_ts': '1695827194.721599', 'channel_type': 'channel'}, 'type': 'event_callback', 'event_id': 'Ev05TZ89JU1L', 'event_time': 1695827194, 'authorizations': [{'enterprise_id': None, 'team_id': 'T057SAAS0K0', 'user_id': 'U05RJ4R1V1D', 'is_bot': True, 'is_enterprise_install': False}], 'is_ext_shared_channel': False, 'event_context': '4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU3U0FBUzBLMCIsImFpZCI6IkEwNVJTMFI0N1NBIiwiY2lkIjoiQzA1VDJTVTM1RlgifQ'}.
The request to the Slack API failed. (url: https://www.slack.com/api/reactions.add, status: 200)
The server responded with: {'ok': False, 'error': 'already_reacted'}
2023-09-27 16:06:35 [   ERROR] Failed to run a request listener: The request to the Slack API failed. (url: https://www.slack.com/api/reactions.add, status: 200)
The server responded with: {'ok': False, 'error': 'already_reacted'}, session: s_393286281