Open ftomassetti opened 1 week ago
The invalid string length means that the retrieve string is too long?
We've seen this one before, I think. Let me search for a bit.
There was #49 . I thought we remedied that already by only using JSON.stringify
in batches. Why is that not enough? Should the batch size be 1?
There was https://github.com/LionWeb-io/lionweb-repository/issues/49 . I thought we remedied that already by only using JSON.stringify in batches.
In https://github.com/LionWeb-io/lionweb-repository/pull/50 we built the JSON manually on a buffer and not directly on a string. For example:
const bufferHolder = new BufferHolder()
bufferHolder.write("[")
classifierNodes.forEach((element, index)=>{
if (index != 0) {
bufferHolder.write(",")
}
bufferHolder.write(`{"language"="${element.language}",`)
bufferHolder.write(`"classifier"="${element.classifier}",`)
bufferHolder.write(`"ids"=[`)
this.serializeInBufferIDsList(bufferHolder, element.ids, limit)
bufferHolder.write(`], "size"=${element.size}}\n`)
})
bufferHolder.write("]")
return bufferHolder.getBuffer()
This was a manual process applied to a couple of requests. Now we are seeing a similar problem in another request. We could solve it in the same way, but it would be invasive and error-prone, while using a library that does what JSON.stringify
does but on a stream, could be simpler, more robust, and easily applicable to all responses.
For example, we could change lionwebResponse
:
export function lionwebResponse<T extends LionwebResponse>(response: Response, status: number, body: T): void {
response.status(status)
// previously: response.send(body) -> this caused some internal part of express to call JSON.stringify(body)
new JsonStreamStringify(body).pipe(response);
}
This is something I need to test, but hopefully should do what I did manually in #50 , just better
I agree: JSONStream
seems to be what we need, rather than assembling responses from partial JSON.stringify
s.
With a recent version of the repository, on a new machine, I get this error, which I was not getting before:
We may explore stream serialization, for example using
JSONStream