Page MenuHomePhabricator

SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data coming from worker-abusefilter.js
Closed, ResolvedPublic

Description

A significant amount of errors are coming from worker-abusefilter.js, for example https://logstash.wikimedia.org/app/dashboards#/doc/logstash-*/logstash-2021.02.10?id=YKJ7i3cBjr5R1RLC-QVJ usually a large amount from a single client.

No stack trace provided.

Event Timeline

The lack of a stacktrace or something is quite problematic, but this is probably the faulty line. Somehow, the API call is not returning valid JSON. It's hard to provide an explanation without knowing what the response was, but personally, 99% of the times I've seen a similar error is because something fails on the PHP side, causing a fatal error. The problem is, I cannot find any error on logstash.

It could possibly be sending the HTML associated with a server error. I've seen those quite frequently. Best to be defensive here and wrap in a try / catch block when using XMLHttpRequest

It could possibly be sending the HTML associated with a server error. I've seen those quite frequently. Best to be defensive here and wrap in a try / catch block when using XMLHttpRequest

Yeah, that was my theory, but I couldn't find any AbuseFilter-related error on logstash for that time. Anyway yes, catching any exception seems a good idea. In case of failure, how can I log the response body so it's visible on logstash?

If you have access to the mw object in the worker you can log directly

Example:

https://gerrit.wikimedia.org/r/c/mediawiki/core/+/663025

The client should check the status code (and perhaps the content-type) before attempting to parse the response body.

If you have access to the mw object in the worker you can log directly

Example:

https://gerrit.wikimedia.org/r/c/mediawiki/core/+/663025

Heh, unfortunately no, otherwise we'd be using mw.Api which would do all these checks for us.

The client should check the status code (and perhaps the content-type) before attempting to parse the response body.

I'm going to implement this, but also adding a try/catch in case of something else that's also unexpected.

Change 663655 had a related patch set uploaded (by Daimona Eaytoy; owner: Daimona Eaytoy):
[mediawiki/extensions/AbuseFilter@master] Check response code and prevent exception in worker-abusefilter

https://gerrit.wikimedia.org/r/663655

Change 663655 merged by jenkins-bot:
[mediawiki/extensions/AbuseFilter@master] Check response code and prevent exception in worker-abusefilter

https://gerrit.wikimedia.org/r/663655