升级到 RestEasy 4 后出现 StackOverflowError。5.x

StackOverflowError after upgrading to RestEasy 4.5.x

从 4.4.2 升级到 RestEasy 到 4.5.2 后,我在返回带有实体 InputStream 的响应时得到 WhosebugError。 返回基本的 10MB 流失败。

可使用非常基本的代码重现错误:

@Path("/")
public class TestResource {

    @GET
    @Produces(MediaType.APPLICATION_OCTET_STREAM)
    @Path("/{size}")
    public Response donwload(@PathParam("size") long size) {
        return Response.ok(new NullInputStream(size)).build();
    }
}

请求:

localhost:8000/1000000  ==> OK
localhost:8000/10000000 ==> WhosebugError

我得到:

org.eclipse.jetty.server.HttpChannelOverHttp.handleException(HttpChannelOverHttp.java:488) :  java.lang.WhosebugError: null
        at org.eclipse.jetty.util.BufferUtil.fill(BufferUtil.java:503)
        at org.eclipse.jetty.server.HttpOutput.write(HttpOutput.java:791)
        at org.jboss.resteasy.plugins.server.servlet.HttpServletResponseWrapper$DeferredOutputStream.write(HttpServletResponseWrapper.java:153)
        at org.jboss.resteasy.plugins.server.servlet.HttpServletResponseWrapper$AsyncOperation.work(HttpServletResponseWrapper.java:41)
        at org.jboss.resteasy.plugins.server.servlet.HttpServletResponseWrapper$DeferredOutputStream.queue(HttpServletResponseWrapper.java:219)
        at org.jboss.resteasy.plugins.server.servlet.HttpServletResponseWrapper$DeferredOutputStream.asyncWrite(HttpServletResponseWrapper.java:180)
        at org.jboss.resteasy.util.CommitHeaderAsyncOutputStream.asyncWrite(CommitHeaderAsyncOutputStream.java:94)
        at org.jboss.resteasy.plugins.providers.ProviderHelper.writeTo(ProviderHelper.java:171)
        at org.jboss.resteasy.plugins.providers.ProviderHelper.lambda$writeTo(ProviderHelper.java:172)
        at java.base/java.util.concurrent.CompletableFuture.uniComposeStage(CompletableFuture.java:1106)
        at java.base/java.util.concurrent.CompletableFuture.thenCompose(CompletableFuture.java:2235)
        at java.base/java.util.concurrent.CompletableFuture.thenCompose(CompletableFuture.java:143)
        at org.jboss.resteasy.plugins.providers.ProviderHelper.writeTo(ProviderHelper.java:172)
        at org.jboss.resteasy.plugins.providers.ProviderHelper.lambda$writeTo(ProviderHelper.java:172)
        at java.base/java.util.concurrent.CompletableFuture.uniComposeStage(CompletableFuture.java:1106)
        at java.base/java.util.concurrent.CompletableFuture.thenCompose(CompletableFuture.java:2235)
        at java.base/java.util.concurrent.CompletableFuture.thenCompose(CompletableFuture.java:143)
        at org.jboss.resteasy.plugins.providers.ProviderHelper.writeTo(ProviderHelper.java:172)
        at org.jboss.resteasy.plugins.providers.ProviderHelper.lambda$writeTo(ProviderHelper.java:172)
        ...
        at java.base/java.util.concurrent.CompletableFuture.uniComposeStage(CompletableFuture.java:1106)
        at java.base/java.util.concurrent.CompletableFuture.thenCompose(CompletableFuture.java:2235)
        at java.base/java.util.concurrent.CompletableFuture.thenCompose(CompletableFuture.java:143)
        at org.jboss.resteasy.plugins.providers.ProviderHelper.writeTo(ProviderHelper.java:172)
        at org.jboss.resteasy.plugins.providers.ProviderHelper.lambda$writeTo(ProviderHelper.java:172)
        ...

调试你的问题后,我认为restEasy没有问题。根本原因是默认的 JVM 配置没有为堆栈分配足够的内存。如果你自己设置JVM栈帧大小大于10M,就不会出现这个错误。

下面是我在Idea中的配置。我为堆栈框架设置了 16M。

代码运行良好,10M可下载

我报告了这个错误 https://issues.redhat.com/browse/RESTEASY-2526,它已经在

之后得到解决