Prevent IllegalStateException on close #12
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
TL;DR: The committed code will not close the inner output-stream, write-body-to-stream will close that one for us and since it is a proxy that calls complete on the AsyncContext we did trigger it twice, provoking the IllegalStateException
Please accept my pull request. I noticed a minor problem where an IllegalStateException was thrown after sending asynchronous data and then closing the channel. Code like the example from the readme.
According to my analysis this might happen if
complete
is called multiple times.complete
is called at the following point by ring: https://github.com/ring-clojure/ring/blob/1.9.0/ring-servlet/src/ring/util/servlet.clj#L129It is called in a proxy method to the output stream.
write-body-to-stream
will callclose
on that stream for the user: https://github.com/ring-clojure/ring/blob/1.9.0/ring-core/src/ring/core/protocols.clj#L12So when
ring-sse
putsoutput-stream
inside of thewith-open
block it will be "closed" twice andcomplete
will be called twice causing the Exception.I did not get the exception with the following changes.