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

Error: An unknown error occurred #209

Open
rromanw opened this issue Feb 2, 2021 · 3 comments
Open

Error: An unknown error occurred #209

rromanw opened this issue Feb 2, 2021 · 3 comments

Comments

@rromanw
Copy link

rromanw commented Feb 2, 2021

When connected to server, exactly after 30 second I receive " facebook - Error: An unknown error occurred".
When debugging and putting breakpoint into fb_http_request_send after third hit after the connect it makes this graphql request:

About to send HTTP request:
POST /graphql HTTP/1.1
Host: graph.facebook.com
Authorization: OAuth <something>
User-Agent: Facebook plugin / BitlBee / 1.2.1 [FBAN/Orca-Android;FBAV/537.0.0.31.101;FBBV/14477681]
Connection: Close
Accept: */*
Content-Length: 314
Content-Type: application/x-www-form-urlencoded

method=get&format=json&query_id=10153919752026729&api_key=<something>device_id=<something>&query_params=%7B%222%22%3A%22true%22%2C%221%22%3A6%2C%2212%22%3A%22true%22%2C%2213%22%3A%22false%22%7D&fb_api_req_friendly_name=ThreadListQuery&locale=en_US&sig=<something>

After sending this a large debug log is printed about parsing some data from server. I just picked a few lines that might be useful (don't know what exactly is happening).

[INFO] facebook: Reading message (topic: /t_p)
[INFO] facebook: Reading message (topic: /t_ms)
[INFO] facebook: Reading message (topic: /orca_typing_notifications)
[INFO] facebook: Reading message (topic: /t_ms)
[INFO] facebook: Reading message (topic: /orca_typing_notifications)
[INFO] facebook: Reading message (topic: /orca_typing_notifications)
[INFO] facebook: Reading message (topic: /orca_typing_notifications)
[INFO] facebook: Reading message (topic: /orca_typing_notifications)
[INFO] facebook: Reading message (topic: /orca_typing_notifications)
[INFO] facebook: Reading message (topic: /t_ms)
[INFO] facebook: Reading message (topic: /orca_typing_notifications)
[INFO] facebook: Reading message (topic: /orca_typing_notifications)
[INFO] facebook: Reading message (topic: /orca_typing_notifications)
[INFO] facebook: Reading message (topic: /orca_typing_notifications)
[INFO] facebook: Reading message (topic: /orca_typing_notifications)

Ultimatelly this appears in the log, seeming that the original request fails:

HTTP response headers:
HTTP/1.1 500 Internal Server Error
Access-Control-Expose-Headers: X-FB-Debug, X-Loader-Length
Access-Control-Allow-Methods: OPTIONS
Expires: Sat, 01 Jan 2000 00:00:00 GMT
Content-Type: application/json; charset=UTF-8
facebook-api-version: v1.0
Access-Control-Allow-Credentials: true
x-fb-request-id: AdF8_86o1Dy_JCfeB8kI0KW
Strict-Transport-Security: max-age=15552000; preload
x-fb-trace-id: GYfjQ8RlGLf
x-fb-rev: 1003253259
Cache-Control: private, no-cache, no-store, must-revalidate
Pragma: no-cache
Vary: Origin
Access-Control-Allow-Origin: https://facebook.com
X-FB-Debug: CjNfgkKkAoOs65riD40rJ41bYYIxdWtmeirgN3hZwQCi7gAw3Kaj1xA9TaUAm3J6CSrurAKX7Y8YBeROfGriVg==
Date: Tue, 02 Feb 2021 18:26:17 GMT
X-FB-Connection-Quality: EXCELLENT; q=0.9, rtt=15, rtx=0, c=10, mss=1380, tbw=3254, uplat=30124
Alt-Svc: h3-29=":443"; ma=3600,h3-27=":443"; ma=3600
Connection: close
Content-Length: 77

Finishing HTTP request with status: 500 Internal Server Error
[INFO] facebook: POST Response (0x555c4b701f80): https://graph.facebook.com/graphql (500 Internal Server Error)
[INFO] facebook:   HTTP/1.1 500 Internal Server Error
[INFO] facebook:   Access-Control-Expose-Headers: X-FB-Debug, X-Loader-Length
[INFO] facebook:   Access-Control-Allow-Methods: OPTIONS
[INFO] facebook:   Expires: Sat, 01 Jan 2000 00:00:00 GMT
[INFO] facebook:   Content-Type: application/json; charset=UTF-8
[INFO] facebook:   facebook-api-version: v1.0
[INFO] facebook:   Access-Control-Allow-Credentials: true
[INFO] facebook:   x-fb-request-id: AdF8_86o1Dy_JCfeB8kI0KW
[INFO] facebook:   Strict-Transport-Security: max-age=15552000; preload
[INFO] facebook:   x-fb-trace-id: GYfjQ8RlGLf
[INFO] facebook:   x-fb-rev: 1003253259
[INFO] facebook:   Cache-Control: private, no-cache, no-store, must-revalidate
[INFO] facebook:   Pragma: no-cache
[INFO] facebook:   Vary: Origin
[INFO] facebook:   Access-Control-Allow-Origin: https://facebook.com
[INFO] facebook:   X-FB-Debug: CjNfgkKkAoOs65riD40rJ41bYYIxdWtmeirgN3hZwQCi7gAw3Kaj1xA9TaUAm3J6CSrurAKX7Y8YBeROfGriVg==
[INFO] facebook:   Date: Tue, 02 Feb 2021 18:26:17 GMT
[INFO] facebook:   X-FB-Connection-Quality: EXCELLENT; q=0.9, rtt=15, rtx=0, c=10, mss=1380, tbw=3254, uplat=30124
[INFO] facebook:   Alt-Svc: h3-29=":443"; ma=3600,h3-27=":443"; ma=3600
[INFO] facebook:   Connection: close
[INFO] facebook:   Content-Length: 77
[INFO] facebook:   
[INFO] facebook:   {"error":{"code":1,"message":"An unknown error occurred","error_subcode":99}}

My guess is, that the plugin tries to get some status information that is too big and the server refuses to serve it, which in response causes the plugin to end the session and reconnect.
This doesn't happen the whole time, sometimes the plugin works just fine half a day or something like that.

Any idea, what might be wrong?

@rromanw
Copy link
Author

rromanw commented Feb 2, 2021

When I ignore this error like this:

diff --git a/facebook/facebook-api.c b/facebook/facebook-api.c
index b452ccd..3aa3f74 100644
--- a/facebook/facebook-api.c
+++ b/facebook/facebook-api.c
@@ -2105,6 +2105,8 @@ fb_api_error(FbApi *api, FbApiError error, const gchar *format, ...)
 void
 fb_api_error_emit(FbApi *api, GError *error)
 {
+    printf("An error occurred, we will consume it\n");
+    return;
     g_return_if_fail(FB_IS_API(api));
     g_return_if_fail(error != NULL);

Bitlbee works fine. Not sure, what the graphql query is trying to accomplish but simply removing it could solve the problem?

@rromanw
Copy link
Author

rromanw commented Feb 3, 2021

I fixed the problem locally with the ugliest patch. It also contains code that kinda mitigates (in a horrible way, include unistd and sleep(2) ) the #73 mega annoying bug. If someone feels like fixing this in a proper way, here is the patch for some hints:

diff --git a/facebook/facebook-api.c b/facebook/facebook-api.c
index b452ccd..7c6ebda 100644
--- a/facebook/facebook-api.c
+++ b/facebook/facebook-api.c
@@ -18,6 +18,7 @@
 #include <bitlbee.h>
 #include <stdarg.h>
 #include <string.h>
+#include <unistd.h>

 #include "facebook-api.h"
 #include "facebook-http.h"
@@ -687,20 +688,26 @@ fb_api_json_chk(FbApi *api, gconstpointer data, gssize size, JsonNode **node)
     root = fb_json_node_new(data, size, &err);
     FB_API_ERROR_EMIT(api, err, return FALSE);

-    values = fb_json_values_new(root);
-    fb_json_values_add(values, FB_JSON_TYPE_INT, FALSE, "$.error_code");
-    fb_json_values_add(values, FB_JSON_TYPE_STR, FALSE, "$.error.type");
-    fb_json_values_add(values, FB_JSON_TYPE_STR, FALSE, "$.errorCode");
-    fb_json_values_update(values, &err);
+    // it would have to be error.code and error.message, it has different format
+    if (strstr(data, "An unknown error occurred")) {
+      code = 1;
+      str = "An unknown error occurred";
+    } else {
+      values = fb_json_values_new(root);
+      fb_json_values_add(values, FB_JSON_TYPE_INT, FALSE, "$.error_code");
+      fb_json_values_add(values, FB_JSON_TYPE_STR, FALSE, "$.error.type");
+      fb_json_values_add(values, FB_JSON_TYPE_STR, FALSE, "$.errorCode");
+      fb_json_values_update(values, &err);

-    FB_API_ERROR_EMIT(api, err,
-        g_object_unref(values);
-        json_node_free(root);
-        return FALSE
-    );
+      FB_API_ERROR_EMIT(api, err,
+          g_object_unref(values);
+          json_node_free(root);
+          return FALSE
+      );

-    code = fb_json_values_next_int(values, 0);
-    str = fb_json_values_next_str(values, NULL);
+      code = fb_json_values_next_int(values, 0);
+      str = fb_json_values_next_str(values, NULL);
+    }

     if ((g_strcmp0(str, "OAuthException") == 0) || (code == 401)) {
         errc = FB_API_ERROR_AUTH;
@@ -719,6 +726,16 @@ fb_api_json_chk(FbApi *api, gconstpointer data, gssize size, JsonNode **node)
         success = FALSE;
     }

+    if ((code == 1) && strstr(str, "An unknown error occurred")) {
+        fb_util_debug_info("Ignoring 500 error which occurs 30s after connect hopefully...\n");
+        errc = FB_API_ERROR_NONFATAL;
+        success = FALSE;
+
+        fb_api_error(api, errc, "%s", str);
+        json_node_free(root);
+        return FALSE;
+    }
+
     str = fb_json_values_next_str(values, NULL);

     if ((g_strcmp0(str, "ERROR_QUEUE_NOT_FOUND") == 0) ||
@@ -2173,7 +2190,7 @@ fb_api_attach(FbApi *api, FbId aid, const gchar *msgid, FbApiMessage *msg)
     prms = fb_http_values_new();
     fb_http_values_set_str(prms, "mid", msgid);
     fb_http_values_set_strf(prms, "aid", "%" FB_ID_FORMAT, aid);
-
+    sleep(2);
     req = fb_api_http_req(api, FB_API_URL_ATTACH, "getAttachment",
                           "messaging.getAttachment", prms,
                           fb_api_cb_attach);

@dequis
Copy link
Member

dequis commented Feb 5, 2021

I think ThreadListQuery is for listing groupchats

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

No branches or pull requests

2 participants