Giter Site home page Giter Site logo

Comments (11)

rnagpal avatar rnagpal commented on July 18, 2024

I haven't tested this completely but

Can you try replacing:

self.retry_after_in_milliseconds = exception.retry_after_in_milliseconds

with:

self.retry_after_in_milliseconds = exception.headers[http_constants.HttpHeaders.RetryAfterInMilliseconds]

and see if that resolves the issue.

Regards,
Rajesh

from azure-cosmos-python.

bmachin avatar bmachin commented on July 18, 2024

Hi Rajesh, first of all, thanks for your great work!

I have two things to comment here:

  1. In the Execute function, notice that sleep is called with a parameter in milliseconds, but it expects it in seconds, so, it will sleep for way too long.
  2. In the _CheckIfRetryNeeded function, the headers attribute of the exception is a list of tuples, in the form (key, value). So, it should either be transformed into a dict, or we should perform a search for the tuple with key http_constants.HttpHeaders.RetryAfterInMilliseconds to get the milliseconds value.

I hope that helps.

Best regards,
Benjamín.-

from azure-cosmos-python.

xou avatar xou commented on July 18, 2024

Hi, i ran into the same problem, implemented the changes @machinbenjamin suggested and created a pull request (#35).

Best Regards,

Niko

from azure-cosmos-python.

 avatar commented on July 18, 2024

Thanks for the PR. if you could add a new test for this PR we will accept and push a new version.

from azure-cosmos-python.

xou avatar xou commented on July 18, 2024

Hi,

thanks for the quick response. Is there a recommended way to test this kind of error? As far as I can see, the error tests in test/crut_test.py connect to an actual documentdb instance and rely on an invalid request, such missing permissions. Testing that a request-rate exceeded error is handled correctly using an actual documentdb instance would depend a lot on timing (and the connection speed of the machine the test is running on).

So, basically, I could see two approaches:

  • Spam a documentdb collection with ~50k requests as fast as possible, and hope that at least one of them throws a rate limit exceeded/retry-after. So basically, that something like for i in range(0, 50000): document_client.query("SELECT * FROM coll_0") does not throw an exception (?)
  • Fake/Mock the connection to the documentdb, for example by creating something like a MockHTTPsConnection, and overwriting the HTTPsConnection class in the pydocumentdb.https_connection module for the unit test.

What would you recommend? Are there maybe similar tests in the dotnet/java documentdb clients? (I had a look, but couldn't find any....)

Regards,
Niko

from azure-cosmos-python.

xou avatar xou commented on July 18, 2024

If you're interested, i've hacked together a testcase for approach 2 here:

https://gist.github.com/xou/f97547b98a38ea8e8f03

The "on continuation" testcase fails with the old version, and succeeds with the PR applied. The "fail immediately" testcase fails in both versions, unsure where the problem is exactly (can look into it later).

from azure-cosmos-python.

 avatar commented on July 18, 2024

looks good. are you able to add the test in to the existing tests - https://github.com/Azure/azure-documentdb-python/tree/master/test

from azure-cosmos-python.

xou avatar xou commented on July 18, 2024

Hi,

I've cleaned the test up a bit and added it to the PR. As mentioned above, one test currently fails and is disabled in the PR. Maybe someone with more Azure experience than me can comment on this, how does Azure respond when the rate limit is exceeded on the first request? Is x-ms-continuation set in that case?

I'm guessing that the problem might be that in query_iterable.py/fetch_items, the if not self.has_started: self._has_started = True should happen after self._fetch_function(...) has been called. self._fetch_function might throw an exception (after _has_started is set), and if the BackoffRetryUtility calls fetch_items again, it will not enter the while loop and return immediately; with an empty result.

Cheers,

Niko

from azure-cosmos-python.

 avatar commented on July 18, 2024

awesome. thank you. will take a look now.

from azure-cosmos-python.

 avatar commented on July 18, 2024

if you hit the 429 on the first request you will not get a continuation token. it will simply fail with the 429 and the retry-after header will be set in the response.

from azure-cosmos-python.

 avatar commented on July 18, 2024

fixed with PR #35

from azure-cosmos-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.