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

bodhi API sometimes returns responses with empty bodies instead of JSON #4044

Open
decathorpe opened this issue May 31, 2020 · 7 comments
Open
Labels
API Issues related to Bodhi's REST API

Comments

@decathorpe
Copy link

As the issue title states, sometimes, but it seems especially when bodhi is "under load", or when setting rows_per_page parameter to a bigger value than the default (e.g. 100), querying the bodhi REST API yields server responses with empty HTTP message bodies, but a "success" HTTP code.

This leads to all kinds of problems (and it's something that I have to actively work around in my bodhi rust client bindings by having a special failure case for "successful" responses with empty response bodies instead of valid JSON).

Since this is a transient / random issue, I don't have exact steps to reproduce it, except for doing some API requests until you get a response with an empty HTTP body instead of JSON.

@decathorpe decathorpe changed the title bodhi API sometimes returnes responses with empty bodies instead of JSON bodhi API sometimes returnes responss with empty bodies instead of JSON May 31, 2020
@decathorpe decathorpe changed the title bodhi API sometimes returnes responss with empty bodies instead of JSON bodhi API sometimes returnes respons with empty bodies instead of JSON May 31, 2020
@decathorpe decathorpe changed the title bodhi API sometimes returnes respons with empty bodies instead of JSON bodhi API sometimes returns responses with empty bodies instead of JSON May 31, 2020
@mattiaverga mattiaverga added the API Issues related to Bodhi's REST API label Jun 9, 2020
@mattiaverga
Copy link
Contributor

Can you post an example query for which you see the problem? What model are you quering? Updates?

@decathorpe
Copy link
Author

It happens intermittently for almost all endpoints, including comments, updates, and overrides. Querying packages and users seem to be mostly unaffected, and releases returns too few values to be a good data point.

I've tried to reproduce it today, and running this python3 script in two terminals side by side eventually triggered the bug (after a minute or so):

import requests

while True:
    requests.get("https://bodhi.fedoraproject.org/overrides/?rows_per_page=100&page=10&releases=EPEL-8").json()

This crashes with an exception as soon as an empty response is encountered, because an empty string is not valid JSON.

An empty response was returned from bodhi in the first terminal (simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)), and invalid JSON in the second terminal (simplejson.errors.JSONDecodeError: Unterminated string starting at: line 1 column 67028577 (char 67028576)).

@mattiaverga
Copy link
Contributor

Oh, well, the problem seems to be in the nearly 300 buildroot overrides for EPEL-8 from tdawson.
For example https://bodhi.fedoraproject.org/overrides/xdg-desktop-portal-kde-5.18.4-1.el8.1
Trying to load a hundred of them will cause a timeout and the above error.

All of these had their notes updated a million times and at every update the new text was appended to the existing, causing them to become gigantic...
I don't know how that user submitted and updated all those BRs, but I suppose they made something really wrong. From our side I suppose we could just set a maximum char limit to BR notes field to prevent that.

@cverna what do you think? Since this will bring a db migration, how should we handle existing records with more than the new limit? Should we just discard everything beyond the limit?
And what about new entries? Since resubmitting a BR will append the new notes, should we raise an error, or discard the existing and add the new notes?

@decathorpe
Copy link
Author

I don't think this is a timeout issue. The returned HTTP response has a 200 code, just an empty response body. I don't see how that's possible from looking at the bodhi server code.

@mattiaverga
Copy link
Contributor

yeah, I misspoke. I mean that the object serialization routine hits some timeouts and sends out data before finishing the object when we try to access those overrides.

I've looked into the code and that happened because every time a BRO is submitted as new, but another BRO with the same build already exists, the old one is used and the new notes are added. So, if one repeatedly create a BRO for the same build nvr, we will end up with gigantic notes, as the example I posted.

I'm going to submit a PR to avoid that, by limiting override notes to a maximum of XXX chars (500? 1.000?) and dropping the older lines in a situation like this.
That's quite ready, I only need to write unit tests (and decide the amount of chars, suggestions welcome).

And we will need to truncate the notes of those problematic overrides manually with a direct query on the database, but that's beyond my privileges... I can prepare the appropriate query to reduce work to admins, if needed.

@decathorpe
Copy link
Author

That should certainly help. But unless today is a day where I should not think about programming, then this will not address the underlying issue where sometimes faulty responses are sent?

@mattiaverga
Copy link
Contributor

OK, I've posted a PR that in future should prevent a situation like this.
About the existing overrides that kills the JSON response, I will open a request on Fedora-infra asking to manually fix those, a simple query like
UPDATE buildroot_overrides SET notes = LEFT(notes, 2000) WHERE LENGTH(notes) > 2000;
should be enough. But I'll wait to ask until the datacenter move is done and the busy guys have some time to look at it.

I'll leave this ticket open as a remainder for the faulty responses, but I can't say what closes the connection while the data is still flowing, if it's on to the server or the client side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Issues related to Bodhi's REST API
Projects
None yet
Development

No branches or pull requests

2 participants