Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bitbucket Rate Limit Handling #354

Open
fullben opened this issue Sep 27, 2022 · 5 comments
Open

Bitbucket Rate Limit Handling #354

fullben opened this issue Sep 27, 2022 · 5 comments
Assignees

Comments

@fullben
Copy link

fullben commented Sep 27, 2022

In a project of mine, where I'm using this library, I ended up tripping the Bitbucket request rate limit configured for the user I am using for authenticating with a Bitbucket server.

This happened when calling various paged API endpoints in quick succession. As a result, the Page objects returned by the library methods would suddenly contain Error objects containing information about some JSON parsing issue.

I found determining the source of my issue rather difficult, as the Error objects provided by the Bitbucket REST library only mentioned issues with parsing the response. Only upon checking the Bitbucket server rate limiting options and enabling logging for jclouds, I was able to understand the problem, as a corresponding 429 response will be logged by jclouds whenever the parse issue occurs.

I also understand that modifying the rate limit settings for my Bitbucket user can mitigate this issue, but at the same time I feel like the library should be able to deal a bit more graceful with this scenario.

Expected Behavior

I would either expect there to be a configuration option for dealing with rate limiting (maybe I missed it?), or for the Error object to at least contain some more meaningful information.

Current Behavior

When a rate limit is tripped by the library, the Bitbucket remote responds with a 429 and a JSON object the library does not seem to understand. The corresponding Error object will only provide information about JSON parsing issues:

exceptionName: "com.google.gson.JsonSyntaxException"
message: "Failed to parse output: message=com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 9 path $"

This in turn makes it impossible for me to programmatically identify this error as a rate limit issue.

Context

Calling various endpoints in quick succession for acquiring the permission information for all Bitbucket projects and their repositories on a Bitbucket server instance.

Your Environment

Bitbucket REST client lib version 3.0.2
Bitbucket server instance version 7.6.17

@cdancy cdancy self-assigned this Sep 27, 2022
@cdancy
Copy link
Owner

cdancy commented Sep 27, 2022

@fullben aahhh ... yeah I've never hammered away on Bitbucket before to trigger any rate-limits. Do those exist across the board for all endpoints? I can put in a fix for this to catch the rate-limit response and return something proper instead of the default "json parse exception" that you see which is admittedly less than ideal.

@fullben
Copy link
Author

fullben commented Sep 27, 2022

@cdancy rate limiting in Bitbucket is user-based, as far as I can tell (see the link from my original post). So I'm assuming it's consistent behavior across all endpoints.
A better error description would be great. But tbh, I was kinda hoping jclouds or the lib itself had some rate limit error handling feature I simply just couldn't find... :)

@cdancy
Copy link
Owner

cdancy commented Sep 27, 2022

@fullben we could certainly wire something up and there might be something we can leverage ... I've just never done so. Something like "retry on http code 429" and allow for some configurability.

@fullben
Copy link
Author

fullben commented Sep 28, 2022

@cdancy I did some digging in the jclouds code... There is this property PROPERTY_MAX_RATE_LIMIT_WAIT (in the Constants). in the jclouds core lib, this property is only utilized in one class, the RateLimitRetryHandler, which is an abstract class. There is no implementation for this class in the core jclouds lib...
I have no clue about jclouds or how your lib uses it, but maybe this is be something that could be leveraged for dealing with Bitbucket rate limiting more gracefully?

@fullben
Copy link
Author

fullben commented Oct 10, 2022

@cdancy bump :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants