You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Occasional segfaults in __lambda65_ when liking tweets #200
Describe the bug
Cawbird occasionally crashes when trying to like a tweet. Iâve only noticed this happening today (twice), but the package manager says I installed the current version on Monday (2020-09-28), so maybe something changed on Twitterâs end.
To Reproduce
Right-click a tweet.
Click the âlikeâ button.
Actual behavior
Very occasionally (I like plenty of tweets and only had two crashes so far), the tweet will stay in the right-clicked view for some seconds (presumably while waiting for the response from Twitter), and then cawbird will crash.
Additional context coredumpctl gdb for the latest crash reports that it happened at src/util/TweetUtils.vala:261 â the âFaving and we didnât get âalready Favedââ line:
try {
call.invoke_async.end (res);
} catch (GLib.Error e) {
var tmp_error = failed_request_to_error (call, e);
// If we can handle it cleanly, pretend it worked if ((status && tmp_error.code !=139) // Faving and we didn't get "already Faved" ||
(!status && tmp_error.code !=144)) { // or un-Faving and didn't get "no such status"
err = tmp_error;
set_favorite_status.callback ();
return;
}
}
p tmp_error reveals that it is 0x0, hence the segfault. e is not null, on the other hand, so it looks like failed_request_to_error turned a non-null error into a null one â itâs not obvious to me where it would do that, though.
Right around the segfault, there are some warnings in the journal (I assume the ordering isnât fully correct):
The JSON messages might indicate that the Twitter error response is supposed to be valid JSON, but for whatever reason itâs not, which confuses Cawbird?
var parser =newJson.Parser();
parser.load_from_data (json);
var obj = parser.get_root().get_object();
var errors = obj.get_array_member("errors");
// Assume there's always at least one, and we just take the first var error = errors.get_element(0).get_object();
// Twitter's error codes don't go above three digits - https://developer.twitter.com/en/docs/basics/response-codes var code = (int)error.get_int_member("code");
var message = error.get_string_member("message");
returnnewGLib.Error.literal (get_error_domain(), code, message);
parser.get_root() seems to be null, and from there on you can follow all the individual calls in the warning messages (the relationship between the Vala and C function names seems pretty clear). And just to make sure, I also confirmed manually that g_error_new_literal (which new GLib.Error.literal(âĶ) presumably compiles to) returns null when called with a null message:
Thanks for investigating. A bit odd that we might get a non-JSON response and not get an error code, but if it does happen then I can imagine it would crash out in a horrible mess!
So far I havenât had another crash but I also havenât seen the new error message I added in the output. I suspect Twitter was just temporarily sending weird error responses (which would also be why I only started seeing the error today), and theyâve fixed it on their end.
Hereâs the diff â Iâll probably send it as a proper pull request tomorrow or so:
diff --git a/src/util/TweetUtils.vala b/src/util/TweetUtils.vala
index 900f68ed..eedf095f 100644
--- a/src/util/TweetUtils.vala+++ b/src/util/TweetUtils.vala@@ -57,7 +57,11 @@ namespace TweetUtils {
*/
var parser = new Json.Parser();
parser.load_from_data (json);
- var obj = parser.get_root().get_object();+ var node = parser.get_root();+ if (node == null) {+ return new GLib.Error (get_error_domain(), 0, "Twitter error is not valid JSON: %s", json);+ }+ var obj = node.get_object();
var errors = obj.get_array_member("errors");
// Assume there's always at least one, and we just take the first
var error = errors.get_element(0).get_object();
â0â is probably not a good error code, but I wasnât sure what else it should be.
I think that's reasonable - 0 can be our "unknown error" code. It saves us having to try and avoid conflicting with other Twitter error codes. The code_to_message will then fall through to the default and return the string that you supplied. The only down-side is that it won't be translated.
Activity
lucaswerkmeister commentedon Oct 2, 2020
Okay, I shouldâve looked at those assertion messages more closely, they correspond directly to the end of the code of
failed_request_to_error:parser.get_root()seems to be null, and from there on you can follow all the individual calls in the warning messages (the relationship between the Vala and C function names seems pretty clear). And just to make sure, I also confirmed manually thatg_error_new_literal(whichnew GLib.Error.literal(âĶ)presumably compiles to) returns null when called with a null message:lucaswerkmeister commentedon Oct 2, 2020
I think I have a fix, currently running a patched version of cawbird to see if the crash still happens :)
IBBoard commentedon Oct 2, 2020
Thanks for investigating. A bit odd that we might get a non-JSON response and not get an error code, but if it does happen then I can imagine it would crash out in a horrible mess!
lucaswerkmeister commentedon Oct 2, 2020
So far I havenât had another crash but I also havenât seen the new error message I added in the output. I suspect Twitter was just temporarily sending weird error responses (which would also be why I only started seeing the error today), and theyâve fixed it on their end.
Hereâs the diff â Iâll probably send it as a proper pull request tomorrow or so:
â0â is probably not a good error code, but I wasnât sure what else it should be.
IBBoard commentedon Oct 3, 2020
I think that's reasonable - 0 can be our "unknown error" code. It saves us having to try and avoid conflicting with other Twitter error codes. The
code_to_messagewill then fall through to the default and return the string that you supplied. The only down-side is that it won't be translated.lucaswerkmeister commentedon Oct 3, 2020
131, âInternal errorâ, might also fit, but maybe itâs better to not reuse a Twitter code, yeah.
Donât crash if Twitter error is not valid JSON
Donât crash if Twitter error is not valid JSON