Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

ChunkedOutput race condition #4493

Closed
yajirobee opened this issue May 27, 2020 · 3 comments · Fixed by #4571
Closed

ChunkedOutput race condition #4493

yajirobee opened this issue May 27, 2020 · 3 comments · Fixed by #4571

Comments

@yajirobee
Copy link

Hi, I faced following error when I use ChunkedOutput for a response. It happens rarely.
I confirmed this happens with jersey 2.30.1 and jetty 9.4.27.v20200227.

ava.lang.IllegalStateException: s=OPEN,api=BLOCKED,sc=false,e=null
    at org.eclipse.jetty.server.HttpOutput.flush(HttpOutput.java:693)
    at org.glassfish.jersey.servlet.internal.ResponseWriter$NonCloseableOutputStreamWrapper.flush(ResponseWriter.java:306)
    at org.glassfish.jersey.message.internal.CommittingOutputStream.flush(CommittingOutputStream.java:263)
    at org.glassfish.jersey.message.internal.OutboundMessageContext.close(OutboundMessageContext.java:840)
    at org.glassfish.jersey.server.ContainerResponse.close(ContainerResponse.java:389)
    at org.glassfish.jersey.server.ChunkedOutput.flushQueue(ChunkedOutput.java:293)
    at org.glassfish.jersey.server.ChunkedOutput.setContext(ChunkedOutput.java:374)
    at org.glassfish.jersey.server.ServerRuntime$Responder.writeResponse(ServerRuntime.java:687)
    at org.glassfish.jersey.server.ServerRuntime$Responder.processResponse(ServerRuntime.java:371)
    at org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:361)
    at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:256)
...

It seems ContainerResponse#close is called outside of synchronized.


I suspect the error happens when ContainerResponse#close is called while another thread is calling write.

@jansupol
Copy link
Contributor

See related

@jansupol
Copy link
Contributor

It's the HttpOutput which is synchronized. To me, it looks like the state changes from BLOCKING to BLOCKED, but not back in its synchronized block.

@jansupol
Copy link
Contributor

HttpOutput really does not look thread safe, but it uses a bunch of synchronized blocks, which is confusing. I did not find any requirement on ServletOutputStream to be thread safe.

@senivam senivam added this to the 2.32 milestone Sep 25, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants