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

rest 接口响应内容大于1kb时触发分块传输,导致报错 #12891

Closed
1 task done
imJYZ opened this issue Aug 14, 2023 · 2 comments
Closed
1 task done

rest 接口响应内容大于1kb时触发分块传输,导致报错 #12891

imJYZ opened this issue Aug 14, 2023 · 2 comments
Labels
type/bug Bugs to being fixed

Comments

@imJYZ
Copy link
Contributor

imJYZ commented Aug 14, 2023

  • I have searched the issues of this repository and believe that this is not a duplicate.

Environment

  • Dubbo version: 3.2.5
  • Java version: 1.8

Steps to reproduce this issue

  1. 使用rest协议暴露一个接口,响应内容大于 1kb
  2. 服务启动后,访问该接口即可触发。

Actual Behavior

实际响应内容会追加报错信息

dubbo rest invoke Internal error, message is null ,and exception type is : class java.lang.IllegalStateException , stacktrace is: 
        at org.apache.dubbo.rpc.protocol.rest.netty.ChunkOutputStream.reset(ChunkOutputStream.java:53)
        at org.apache.dubbo.rpc.protocol.rest.extension.resteasy.ResteasyContext.restOutputStream(ResteasyContext.java:176)
        at org.apache.dubbo.rpc.protocol.rest.extension.resteasy.filter.ResteasyResponseContainerFilterAdapter.filter(ResteasyResponseContainerFilterAdapter.java:62)
        at org.apache.dubbo.rpc.protocol.rest.handler.NettyHttpHandler.executeFilters(NettyHttpHandler.java:137)
        at org.apache.dubbo.rpc.protocol.rest.handler.NettyHttpHandler.handle(NettyHttpHandler.java:107)
        at org.apache.dubbo.rpc.protocol.rest.netty.RestHttpRequestDecoder.lambda$decode$0(RestHttpRequestDecoder.java:67)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at org.apache.dubbo.common.threadlocal.InternalRunnable.run(InternalRunnable.java:41)
        at java.lang.Thread.run(Thread.java:748)
@imJYZ imJYZ added the type/bug Bugs to being fixed label Aug 14, 2023
@CrazyHZM
Copy link
Member

@suncairong163 PTAL

@imJYZ
Copy link
Contributor Author

imJYZ commented Aug 14, 2023

org.apache.dubbo.rpc.protocol.rest.netty.NettyHttpResponse中通过一下方式创建outputstream

os = new ChunkOutputStream(this, ctx, 1000);

org.apache.dubbo.rpc.protocol.rest.netty.ChunkOutputStream 会分块处理长度超过1000的响应内容。

public void write(byte[] b, int off, int len) throws IOException {
        int dataLengthLeftToWrite = len;
        int dataToWriteOffset = off;
        int spaceLeftInCurrentChunk;
        while ((spaceLeftInCurrentChunk = buffer.maxWritableBytes()) < dataLengthLeftToWrite) {
            buffer.writeBytes(b, dataToWriteOffset, spaceLeftInCurrentChunk);
            dataToWriteOffset = dataToWriteOffset + spaceLeftInCurrentChunk;
            dataLengthLeftToWrite = dataLengthLeftToWrite - spaceLeftInCurrentChunk;
            flush();
        }
        if (dataLengthLeftToWrite > 0) {
            buffer.writeBytes(b, dataToWriteOffset, dataLengthLeftToWrite);
        }
    }

org.apache.dubbo.rpc.protocol.rest.extension.resteasy.filter.ResteasyResponseContainerFilterAdapter会在 restOutputStream(response); 时触发异常

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Bugs to being fixed
Projects
None yet
Development

No branches or pull requests

2 participants