quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.63k stars 2.64k forks source link

[RESTEasy Reactive] Streaming JSON with failure #14222

Open cescoffier opened 3 years ago

cescoffier commented 3 years ago

We need to discuss the behavior when the streamed Multi emits a failure.

Imagine something like:

@GET
@Path("/multiX")
public Multi<Person> getMultiX() {
    Person person = new Person();
    person.setFirst("Bob");
    person.setLast("Builder");
    return Multi.createFrom().items(person)
      .onCompletion().failWith(() -> new Exception("boom"));
}

Basically, a failure happening during the streaming. We cannot set the status to 500, as the headers have already been written (BTW, if the failure happens before having sent any item, it should be the case).

What should be the outcome in this case? Should we encode the failure in JSON followed by ] and let the client handle the failure? Should we just end the response abruptly (no ending ])?

ghost commented 3 years ago

/cc @FroMage, @geoand, @stuartwdouglas

geoand commented 3 years ago

I would say just end the response :)

FroMage commented 3 years ago

I dunno, including a json error in the middle of an array is probably Horribly Wrong™…

We can't even put stuff in a tailer HTTP header because you have to declare them in advance, and only in CHUNK.

I can't find any obvious result online about how to handle this.

stuartwdouglas commented 3 years ago

You can't include a JSON error in the middle of a response, that would be really wrong.

IMHO the best thing to do would be to just end the response so the resulting JSON is invalid.