server-client-python icon indicating copy to clipboard operation
server-client-python copied to clipboard

Retry for request in use_server_version

Open ad-m-ss opened this issue 1 year ago • 2 comments

Describe the bug

We are indexing data from multiple Tableau instances as a service provider integrating with Tableau. We observed flaky requests on some instances:

2024-11-01T08:42:57.565777616Z stderr F INFO 2024-11-01 08:42:57,565 server 14 140490986871680 Could not get version info from server: <class 'tableauserverclient.server.endpoint.exceptions.InternalServerError'>
2024-11-01T08:42:57.565846529Z stderr F 
2024-11-01T08:42:57.565851784Z stderr F Internal error 504 at https://XXXX/selectstar/api/2.4/serverInfo
2024-11-01T08:42:57.565860665Z stderr F b'<html>\r\n<head><title>504 Gateway Time-out</title></head>\r\n<body>\r\n<center><h1>504 Gateway Time-out</h1></center>\r\n<hr><center>nginx/1.25.3</center>\r\n</body>\r\n</html>\r\n'
2024-11-01T08:42:57.566048361Z stderr F INFO 2024-11-01 08:42:57,565 server 14 140490986871680 versions: None, 2.4

We observed that the request in use_server_version does not apply retry with exponential backoff, which is a good practice in such scenarios. There is no easy way to implement it, as this is implicit call in __init__.

Versions Details of your environment, including:

  • Tableau Server version (or note if using Tableau Online)
  • Python version
  • TSC library version

To Reproduce Steps to reproduce the behavior. Please include a code snippet where possible.

That issue is transistent.

1/ Initalize SDK:

        self._server = TSC.Server(
            base_url,
            use_server_version=True,
            http_options={"timeout": self.REQUEST_TIMEOUT},
        )

2/ Ensure that network connectivity to Tableau is unreliable and may drop connection.

Results What are the results or error messages received?

See exception above.

ad-m-ss avatar Nov 01 '24 19:11 ad-m-ss

While we consider adding this, there is a way to handle this locally. In the init, set it to False (the default), then call it separately.

self._server = TSC.Server(base_url)
# Wrap the below call in your exponential backoff retry loop.
self._server.use_server_version()

jorwoods avatar Nov 04 '24 21:11 jorwoods

I'm not sure yet whether to build this in, but this can be done by using the existing option to pass in a custom Session_Factory in the initialization call. We probably also need to document that option.

https://github.com/tableau/server-client-python/pull/1111

https://www.peterbe.com/plog/best-practice-with-retries-with-requests

jacalata avatar Jan 03 '25 23:01 jacalata