Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Error while closing the output stream in order to commit response #5774

Open
namedgraph opened this issue Oct 18, 2024 · 2 comments
Open

Error while closing the output stream in order to commit response #5774

namedgraph opened this issue Oct 18, 2024 · 2 comments

Comments

@namedgraph
Copy link

namedgraph commented Oct 18, 2024

Using Jersey 3.1.0 and ApacheConnectorProvider (Apache HTTP Client 4.5.13). Why is this happening?

Looks like the cause is org.apache.http.client.NonRepeatableRequestException: Cannot retry request with a non-repeatable request entity.

Same issue as https://stackoverflow.com/questions/42139436/jersey-client-throws-cannot-retry-request-with-a-non-repeatable-request-entity
See also #4021

18-Oct-2024 11:28:06.185 SEVERE [http-nio-7070-exec-10] org.glassfish.jersey.server.ServerRuntime$Responder.writeResponse Error while closing the output stream in order to commit response.
  org.glassfish.jersey.server.ContainerException: java.util.concurrent.ExecutionException: jakarta.ws.rs.ProcessingException: org.apache.http.client.ClientProtocolException
          at org.glassfish.jersey.servlet.internal.ResponseWriter.getResponseContext(ResponseWriter.java:278)
          at org.glassfish.jersey.servlet.internal.ResponseWriter.writeResponseStatusAndHeaders(ResponseWriter.java:128)
          at org.glassfish.jersey.server.ServerRuntime$Responder$1.getOutputStream(ServerRuntime.java:667)
          at org.glassfish.jersey.message.internal.CommittingOutputStream.commitStream(CommittingOutputStream.java:171)
          at org.glassfish.jersey.message.internal.CommittingOutputStream.flushBuffer(CommittingOutputStream.java:276)
          at org.glassfish.jersey.message.internal.CommittingOutputStream.commit(CommittingOutputStream.java:232)
          at org.glassfish.jersey.message.internal.CommittingOutputStream.close(CommittingOutputStream.java:247)
          at org.glassfish.jersey.message.internal.OutboundMessageContext.close(OutboundMessageContext.java:842)
          at org.glassfish.jersey.server.ContainerResponse.close(ContainerResponse.java:389)
          at org.glassfish.jersey.server.ServerRuntime$Responder.writeResponse(ServerRuntime.java:749)
          at org.glassfish.jersey.server.ServerRuntime$Responder.processResponse(ServerRuntime.java:385)
          at org.glassfish.jersey.server.ServerRuntime$Responder.processResponseWithDefaultExceptionMapper(ServerRuntime.java:633)
          at org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:458)
          at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:269)
          at org.glassfish.jersey.internal.Errors$1.call(Errors.java:248)
          at org.glassfish.jersey.internal.Errors$1.call(Errors.java:244)
          at org.glassfish.jersey.internal.Errors.process(Errors.java:292)
          at org.glassfish.jersey.internal.Errors.process(Errors.java:274)
          at org.glassfish.jersey.internal.Errors.process(Errors.java:244)
          at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:265)
          at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:240)
          at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:697)
          at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:394)
          at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:346)
          at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:357)
          at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:311)
          at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:205)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:223)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158)
          at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:185)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158)
          at org.apache.catalina.filters.HttpHeaderSecurityFilter.doFilter(HttpHeaderSecurityFilter.java:126)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:185)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158)
          at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:177)
          at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
          at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542)
          at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:119)
          at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
          at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690)
          at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
          at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357)
          at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:400)
          at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
          at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:859)
          at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1734)
          at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52)
          at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
          at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
          at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
          at java.base/java.lang.Thread.run(Thread.java:833)
  Caused by: java.util.concurrent.ExecutionException: jakarta.ws.rs.ProcessingException: org.apache.http.client.ClientProtocolException
          at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:396)
          at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2073)
          at org.glassfish.jersey.servlet.internal.ResponseWriter.getResponseContext(ResponseWriter.java:276)
          ... 51 more
  Caused by: jakarta.ws.rs.ProcessingException: org.apache.http.client.ClientProtocolException
          at org.glassfish.jersey.apache.connector.ApacheConnector.apply(ApacheConnector.java:519)
          at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:297)
          at org.glassfish.jersey.client.JerseyInvocation.lambda$invoke$0(JerseyInvocation.java:662)
          at org.glassfish.jersey.client.JerseyInvocation.call(JerseyInvocation.java:697)
          at org.glassfish.jersey.client.JerseyInvocation.lambda$runInScope$3(JerseyInvocation.java:691)
          at org.glassfish.jersey.internal.Errors.process(Errors.java:292)
          at org.glassfish.jersey.internal.Errors.process(Errors.java:274)
          at org.glassfish.jersey.internal.Errors.process(Errors.java:205)
          at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:390)
          at org.glassfish.jersey.client.JerseyInvocation.runInScope(JerseyInvocation.java:691)
          at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:661)
          at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:439)
          at org.glassfish.jersey.client.JerseyInvocation$Builder.put(JerseyInvocation.java:328)
          at com.atomgraph.core.client.EndpointClientBase.put(EndpointClientBase.java:139)
          at com.atomgraph.core.client.EndpointClientBase.put(EndpointClientBase.java:134)
          at com.atomgraph.core.client.GraphStoreClient.putModel(GraphStoreClient.java:178)
          at com.atomgraph.linkeddatahub.resource.Graph.put(Graph.java:248)
          at jdk.internal.reflect.GeneratedMethodAccessor38.invoke(Unknown Source)
          at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.base/java.lang.reflect.Method.invoke(Method.java:568)
          at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory.lambda$static$0(ResourceMethodInvocationHandlerFactory.java:52)
          at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:134)
          at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:177)
          at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:176)
          at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:81)
          at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:478)
          at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:400)
          at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:81)
          at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:261)
          ... 38 more
  Caused by: org.apache.http.client.ClientProtocolException
          at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:187)
          at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
          at org.glassfish.jersey.apache.connector.ApacheConnector.apply(ApacheConnector.java:471)
          ... 66 more
  Caused by: org.apache.http.client.NonRepeatableRequestException: Cannot retry request with a non-repeatable request entity
          at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:108)
          at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
          at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
          ... 68 more
  Caused by: java.net.SocketException: Broken pipe
          at java.base/sun.nio.ch.NioSocketImpl.implWrite(NioSocketImpl.java:420)
          at java.base/sun.nio.ch.NioSocketImpl.write(NioSocketImpl.java:440)
          at java.base/sun.nio.ch.NioSocketImpl$2.write(NioSocketImpl.java:826)
          at java.base/java.net.Socket$SocketOutputStream.write(Socket.java:1035)
          at org.apache.http.impl.conn.LoggingOutputStream.write(LoggingOutputStream.java:74)
          at org.apache.http.impl.io.SessionOutputBufferImpl.streamWrite(SessionOutputBufferImpl.java:124)
          at org.apache.http.impl.io.SessionOutputBufferImpl.flushBuffer(SessionOutputBufferImpl.java:136)
          at org.apache.http.impl.io.SessionOutputBufferImpl.flush(SessionOutputBufferImpl.java:144)
          at org.apache.http.impl.io.ChunkedOutputStream.close(ChunkedOutputStream.java:203)
          at org.glassfish.jersey.message.internal.CommittingOutputStream.close(CommittingOutputStream.java:248)
          at org.glassfish.jersey.client.ClientRequest.doWriteEntity(ClientRequest.java:503)
          at org.glassfish.jersey.client.ClientRequest.writeEntity(ClientRequest.java:458)
          at org.glassfish.jersey.apache.connector.ApacheConnector$1.writeTo(ApacheConnector.java:625)
          at org.apache.http.impl.execchain.RequestEntityProxy.writeTo(RequestEntityProxy.java:121)
          at org.apache.http.impl.DefaultBHttpClientConnection.sendRequestEntity(DefaultBHttpClientConnection.java:156)
          at org.apache.http.impl.conn.CPoolProxy.sendRequestEntity(CPoolProxy.java:152)
          at org.apache.http.protocol.HttpRequestExecutor.doSendRequest(HttpRequestExecutor.java:238)
          at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:123)
          at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:272)
          at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186)
          at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
          ... 70 more
@jansupol
Copy link
Contributor

From the top of my head, this happens when an entity is reused. For instance, there is a proxy that the entity is sent to and the same entity is then sent again to a proper destination. Some entities can only be consumed just once, such as an InputStream. The second time the entity tries to be sent, this exception occurs. The buffered entity can solve it (ClientProperties.REQUEST_ENTITY_PROCESSING, RequestEntityProcessing.BUFFERED).

@namedgraph namedgraph changed the title org.apache.http.client.NonRepeatableRequestException: Cannot retry request with a non-repeatable request entity Error while closing the output stream in order to commit response Oct 18, 2024
@namedgraph
Copy link
Author

Thanks @jansupol . I'm attempting client.property(ClientProperties.REQUEST_ENTITY_PROCESSING, RequestEntityProcessing.BUFFERED) but no luck so far. Would this show up in the HTTP logs somehow? Probably Content-Length should be present on the client request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants