grails-plugins / grails-rxjava

A plugin that integrates Grails with RxJava
Apache License 2.0
11 stars 10 forks source link

A thrown exception in rx.stream(Closure) does not close the event stream connection #2

Closed sbearcsiro closed 7 years ago

sbearcsiro commented 7 years ago

This occurs in the default Tomcat in Grails 3.2.5 though I suspect it will occur in all previous Tomcat versions as well. It appears that the Catalina AsyncContextImpl does not handle an exception thrown by the Runnable passed to start(), so no AsyncListeners are notified. I'm not sure whether this is a bug in Tomcat or not (my Google-fu didn't turn up whether AsyncContext.start() was supposed to notify any listeners).

See a demo here: https://github.com/sbearcsiro/grailsrxdemo. I would expect the EventSource should close and reconnect on the client after the Exception is thrown. Note also that a unit test won't display this problem as the Spring MockAsyncContext executes the start() call on the same thread, so the exception bubbles back into the RxJava Observable which does call onError with the exception.

It seems to me that in the case of a NewObservableResult argument to the RxResultTransformer it should, by default, subscribe on the AsyncContext.start() thread. This would match the behaviour if an Observable is passed in. PR incoming...