Skip to content

Enable automatic retry by a handy way #887

@seratch

Description

@seratch

What's this?

WebClient does not retry HTTP requests in any case. Developers may want to have auto-retries for intermittent and/or recoverable errors. We can consider adding a new option (or its underlying function) for auto-retry on the library side.

Basic Design Idea

The primary option should be a retry configuration like urllib3 offers: https://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html

retry = Retry(connect=5, read=2, redirect=5, ratelimited=10)
client = WebClient(token="xoxb-", retry=retry)

WebClient can translate the configuration to an error handling function under the hood. The possible function interface can be as below (note: this is a completely pseudo code):

def retry_handler(client, req, error, retry_num) -> Union[SlackResponse, Exception]:
     if is_recoverable(error):
         return client.retry(req)
     else:
         return error

client = WebClient(token="xoxb-", retry_handler=retry_handler)

Most developers just need retry config but some may want to take full control of the logic (e.g., implementing exponential backoff retries etc).

Factors to Consider

  • Provide the same interface to both AsyncWebClient and WebClient; this means the compatibility with AIOHTTP must be evaluated before deciding the interface
  • Provide the option to WebClient and WebhookClient
  • Enable overwriting per endpoint; developers may want to turn retries on only for a particular endpoint
  • Smooth integration with Bolt for Python; the design should not block giving the config from App class constructor
  • Handle ratelimited errors appropriately

... what else?

Category (place an x in each of the [ ])

  • slack_sdk.web.WebClient (Web API client)
  • slack_sdk.webhook.WebhookClient (Incoming Webhook, response_url sender)
  • slack_sdk.models (UI component builders)
  • slack_sdk.oauth (OAuth Flow Utilities)
  • slack_sdk.rtm.RTMClient (RTM client)
  • slack_sdk.signature (Request Signature Verifier)

Requirements

Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.

Metadata

Metadata

Assignees

Labels

Version: 3xdiscussionM-T: An issue where more input is needed to reach a decisionenhancementM-T: A feature request for new functionalityweb-client

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions