-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
SimpleJSON library has added spaces to API responses #3012
Comments
the current behaviour of Matrix is that the JSON sent over federation does not have to be in canonical form, and is entirely allowed to include whitespace. (And meanwhile the whole CS API is certainly standard RFC7159 JSON and is absolutely allowed to include whitespace; any client which chokes on whitespace is categorically broken.) If folks implement homeservers which assume that JSON received over federation is canonicalised, then the problem is on their side for now. When/if #2951 or https://github.com/matrix-org/matrix-doc/issues/1013 are merged, then everything will have to do the shuffle to go speak canonical JSON over federation, which will resolve this issue. However, we have enough challenges right now supporting synapse and keeping matrix.org online and performant without jumping through new hoops to stop jzk's homeserver from crashing; instead for now he should canonicalise received JSON like everyone else does - or alternatively sit talking his own dialect of Matrix until we can sort the issues above. |
The number of times you have, without prompt, mentioned JZK and their (yet unreleased) homeserver to couch your reasoning for this ἀπολογία is curious, to say the least. Here are the facts
Conclusions on the facts
Involving whitespace in the latest release of Synapse was almost certainly an error. Surely, even an innocent one in the haste of trying to work around an attack on ujson. I see no technical case having been made to justify this on a merit, even something as trivial as:
No. That case wasn't made. The case I see being made here straddles somewhere between "don't know" and "don't care." I think this is unbecoming of patrons to a burgeoning communication protocol that are striving for wider adoption. The only thing worse now is that something absolutely trivial in both its technical inception and its technical resolution has turned into a needless debate. Everyone makes mistakes. Just commit the fix and move on. |
[The original report wasn't clear on whether the change covered just the CS API, or the Federation API too - I was confused by the reference to 'breaking compatibility with clients' in the description. It looks like both are affected] |
I'm afraid I don't agree that matrix.org has a duty to stick to one exact encoding of JSON. Responses are defined as (regular) JSON by the specification, and homeserver implementations are free to format that JSON however they like. JSON is well-specified, and clients should correctly handle any responses which are are so formatted. I'd almost prefer to change things regularly to shake out bad assumptions. Canonical JSON (in particular, the requirement that object keys be sorted) is an unnecessary overhead for things which aren't signed, and we aren't going to specify another almost-JSON-but-not-quite. So JSON it stays, and JSON you must accept. There is an argument that, as an implementation-specific optimisation, synapse could remove whitespace from responses for reasons of conserving bandwidth, however I think the bandwidth involved is trivial, so this is correctly tagged as an 'enhancement'. Still, feel free to send a PR to change it. |
According to your benchmark, simplejson: without sorting:
with sorting:
The overhead for sorting your test vector barely registers above the margin of error. Consider that most federation responses only have a handful of keys, like "pdus" and "auth_chain" ... so that's one big single honking comparison right there. P.S. When you do benchmarks you shouldn't use cpython
Just thought you should know. |
not a bug. |
After switching from
ujson
tosimplejson
, we've started including spaces in JSON response data. This is both not necessary for bandwidth reasons, and could potentially break compatibility with clients that rely on the old response format.Reported by @jzk:matrix.org
The text was updated successfully, but these errors were encountered: