question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enable automatic retry by a handy way

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:8
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
ashvinnihalanicommented, Dec 7, 2020

Also a note, the retry should not only retry the command but retry the recreating the connection. Often times Slack responds with a connection reset by peer when you are trying mass calls and to recover you need to reinitialize the client.

0reactions
nraj-willowcommented, Oct 5, 2021

@seratch Thanks for replying, I found retries are also there in node sdk, Sorry I comment in wrong repo. https://github.com/slackapi/node-slack-sdk/blob/e7ef5289d0154370c65656fba4bbb6ee6f53d7d1/packages/web-api/README.md#automatic-retries

Read more comments on GitHub >

github_iconTop Results From Across the Web

Retry Link - Apollo GraphQL Docs
@apollo/client/link/retry can be used to retry an operation a certain amount of times. This comes in handy when dealing with unreliable communication ...
Read more >
Adding Automatic Retries to Fetch - Mark Michon
One missing feature that can come in handy when making requests is the ability to retry the requests, either on specific response status...
Read more >
Store and Forward Automatic Retry - Ignition
Hi, I am looking for a way to get the store and forward engine to automatically retry. We use the Canary module to...
Read more >
Guide to Spring Retry - Baeldung
A quick and practical guide to implementing retry logic with Spring Retry.
Read more >
Retrying event-driven functions - Google Cloud
This document describes how to enable retrying for event-driven functions. Automatic retrying is not available for HTTP functions.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found