scalacenter/bloop

Malformed jsonrpc method not found responses

Closed this issue · 2 comments

When the Bloop BSP server receives requests that it doesn't support, it often responds with answers like

{
    "id": "6",
    "error": {
        "code": -32601,
        "message": "buildTarget/wrappedSources"
    }
},{
    "error": {
        "code": -32601,
        "message": "buildTarget/wrappedSources"
    },
    "id": "6",
    "jsonrpc": "2.0"
}

That is, the response is malformed, somehow concatenating two JSON objects, separated by a comma. BSP clients fail to parse such a response, and thus do not properly report the method as being unsupported by the BSP server, usually failing with a more severe error (JSON parsing error).

The bug in more detail originates from jsonrpc4s relying on jsoniter-scala to (de)serialize JSON. Since jsoniter-scala 2.10.0, its main methods to write JSON aren't re-entrant anymore (a codec called by a write method shouldn't itself call a write method, for example, because the write methods are stateful and can't be called twice at the same time).

jsonrpc4s needs to use the re-entrant write methods of jsoniter-scala instead, like done here.

Note that the original Scala CLI fork of Bloop doesn't suffer this bug, thanks to scala-cli@12a823a and its use of this jsonrpc fork