> On May 30, 2024, at 08:47, <[email protected]>
> <[email protected]> wrote:
>
> I have a NIO connector with an asynchronous servlet with its write listener
> (working in both tomcat 8.5 and tomcat 10.1.20).
>
> @Override
> public void onWritePossible() throws IOException {
>
> if (this.isFirst) {
> this.os = this.asyncContext.getResponse().getOutputStream();
> this.startIdx = 0;
> this.endIdx = WRITE_BUFFER_SIZE;
> }
Is there any logic somewhere to clear isFirst? If not, the start and end
indices will be reset every time this method is called should os.isReady()
returns false.
> while (this.startIdx < this.endIdx && this.os.isReady()) {
> this.os.write(this.response, this.startIdx, this.endIdx - this.startIdx);
>
> this.startIdx = this.endIdx;
> this.endIdx += WRITE_BUFFER_SIZE;
> if (this.endIdx > this.response.length) this.endIdx =
> this.response.length;
> }
>
> if (this.startIdx == this.endIdx) {
> this.ac.complete();
> }
> }
>
> Only when the response to return is bigger than 32K then:
> 1. Writing the response in chunks of WRITE_BUFFER_SIZE = 32K, sometimes our
> client receives the response in wrong order (complete, all bytes written, but
> in different order).
> 2. Setting a WRITE_BUFFER_SIZE = 8K seems to fix this issue.
>
> But it's weird, this is only happening in this client, we have other
> installations returning responses of megabytes with no issues.
Perhaps this one client has a slow network, so isReady() returns false in that
environment, but not in other ones.
- Chuck
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]