Hi Chuck,

isFirst is initialized to 'true' when the class is instantiated, so that
piece of code is just executed the first time the execution enters the '
onWritePossible' method. Later, within the same 'if', 'isFirst' is set to
false, (not shown in the code, sorry)

Perhaps this one client has a slow network, so isReady() returns false in
that environment, but not in other ones.
--> And how can this be solved?  I mean, no one wants to have a piece of
code that works fine just depending on the network speed. The point is the
whole response is returned back (until the last byte), but not in the
correct order. The responses are xml, so some documents cannot be parsed
correctly, that 's why the alert was thrown on the client side.

This is just a sample, but it's like instead of receiving this:
<response>
        <hotels>
                <hotel>.....</hotel>
                <hotel>...</hotel>
        </hotels>
</response>

The client is receiving this:   

<response>
        <hotels>
                <hot
                <hotel>...</hotel>
        </hotels>
                el>.....</hotel>
</response>

It's like a chunk is received in wrong order.

Thanks!

Joan.

-----Original Message-----
From: Chuck Caldarale <n82...@gmail.com> 
Sent: Thursday, May 30, 2024 7:27 PM
To: Tomcat Users List <users@tomcat.apache.org>
Subject: Re: Write listener question


> On May 30, 2024, at 08:47, <joan.balagu...@ventusproxy.com>
<joan.balagu...@ventusproxy.com> 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: 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