Comments (11)
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.
Hi Rajesh, first of all, thanks for your great work!
I have two things to comment here:
- In the
Execute
function, notice thatsleep
is called with a parameter in milliseconds, but it expects it in seconds, so, it will sleep for way too long. - 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 adict
, or we should perform a search for the tuple with keyhttp_constants.HttpHeaders.RetryAfterInMilliseconds
to get the milliseconds value.
I hope that helps.
Best regards,
Benjamín.-
from azure-cosmos-python.
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.
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.
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 theHTTPsConnection
class in thepydocumentdb.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.
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.
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.
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.
awesome. thank you. will take a look now.
from azure-cosmos-python.
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.
fixed with PR #35
from azure-cosmos-python.
Related Issues (20)
- Query Partitioned Collection HOT 4
- Documentation outdated
- ChangeFeed gets all the history records instead of current record.
- How to send a query or stored procedure execution to a specific region/location ? HOT 1
- Documentation does not include how to create a database with provisioned throughput
- No method get_database_client in CosmosClient HOT 2
- pydocumentdb 2.3.5 install failed with homebrew HOT 3
- synchronized_request._Request is_media sniff bug HOT 1
- When can we expect 4.* release? HOT 2
- Documentation is broken due to bad doc string
- SQL queries with DISTINCT and ORDER BY does not work
- old version pydocumentdb source code is missing
- Missing information HOT 1
- SyntaxWarning: "is not" with a literal
- AttributeError: 'CosmosClient' object has no attribute 'ExecuteStoredProcedure' HOT 5
- Moving to a new repo HOT 2
- enable autoscaling for database HOT 1
- Using Python to connect to cosmosDB throws Authorization header doesn't confirm to the required format HOT 2
- Python SDK - Update Autoscale Throughput HOT 1
- This repo is missing important files HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from azure-cosmos-python.