Joan,

Please don't hijack threads. Start a new message to the list without replying to an existing one.

-chris

On 5/30/24 06:03, joan.balagu...@ventusproxy.com wrote:
Sorry, this issue happens with both Tomcat 8.5.x and 10.1.x.

-----Original Message-----
From: joan.balagu...@ventusproxy.com <joan.balagu...@ventusproxy.com>
Sent: Thursday, May 30, 2024 11:57 AM
To: 'Tomcat Users List' <users@tomcat.apache.org>
Subject: Write listener question

Hello,

I have a NIO connector with an asynchronous servlet with its write listener.

@Override
  public void onWritePossible() throws IOException {

   if (this.isFirst) {
     this.os = this.asyncContext.getResponse().getOutputStream();
     this.startIdx = 0;
     this.endIdx = WRITE_BUFFER_SIZE;
   }
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.

So just a couple of questions:

1. Do you think the implementation of the onWritePossible method above is 
correct?
2. Is it worth to provide a buffered implementation of the ServletOuputStream 
to write the response?


Thanks,

Joan.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to