You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Sumit Bhardwaj <su...@gmail.com> on 2013/02/27 05:05:41 UTC

Issue with Async Servlet onTimeout

Hi,

I am using AsyncContext for implementing a file download app and seeing
issues on the timeout. I am using tomcat 7.0.23  (and have tried on 7.0.28
as well, but seeing the issue in 28 as well)

Here is the code snippet I use

*Servlet*

MyServelt{

......

final AsyncContext asyncContext = request.startAsync(request, response);

asyncContext.setTimeout(60000);

final DownloadChunkTask task = new DownloadChunkTask(asyncContext, input,
curRequestNo);

asyncContext.addListener(task);

....

}

*Async task*

MyTask{


 private final BufferedInputStream fileInputStream;

private final AsyncContext ctx;


MyTask(AsyncContext ctx,

  BufferedInputStream fileInputStream, long requestNo)

  throws IOException

{

this.ctx = ctx;

this.requestNo = requestNo;

this.fileInputStream = fileInputStream;

}


public void onComplete(AsyncEvent asyncEvent) throws IOException {

ctx.complete();

}


public void onTimeout(AsyncEvent asyncEvent) throws IOException {

LOG.warn("Asynchronous request timeout ({})", requestNo);

  onComplete(asyncEvent);

}


public Void call() throws Exception {

private final byte[] buffer = new byte[fileSize];

final int bytesCount = fileInputStream.read(buffer);

*ctx.getResponse().getOutputStream().write(buffer, 0, bytesCount);//The
threads are stuck here.*

}

 Is there any issue in the above code.


what I am facing is that the threads are stuck in the onCall method on the
write call whenever there is a timeout.


Regards,

Sumit

Re: Issue with Async Servlet onTimeout

Posted by Sumit Bhardwaj <su...@gmail.com>.
Hi Chris,

Looks like tomcat 7.0.37 solve this issue.

One question though, I am seeing following error in catalina.out

*java.lang.IllegalStateException: Calling [asyncComplete()] is not valid
for a request with Async state [MUST_COMPLETE]*


do I need to handle something in my code??

Also are there any detailed examples of implementation of AsynListener?

Thanks,
Sumit

On Wed, Feb 27, 2013 at 11:52 AM, Sumit Bhardwaj
<su...@gmail.com>wrote:

> Sure Chris,
>
> would try with 7.0.37
>
> Thanks,
> Sumit
>
>
> On Wed, Feb 27, 2013 at 11:42 AM, Christopher Schultz <
> chris@christopherschultz.net> wrote:
>
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA256
>>
>> Sunit,
>>
>> On 2/26/13 8:05 PM, Sumit Bhardwaj wrote:
>> > Hi,
>> >
>> > I am using AsyncContext for implementing a file download app and
>> > seeing issues on the timeout. I am using tomcat 7.0.23  (and have
>> > tried on 7.0.28 as well, but seeing the issue in 28 as well)
>>
>> Any chance of testing on 7.0.37, the current release? There have been
>> a number of fixes to the async portions of Tomcat since 7.0.23/28,
>> though none of the changelog descriptions jump out at me as being
>> obviously relevant.
>>
>> - -chris
>> -----BEGIN PGP SIGNATURE-----
>> Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
>> Comment: GPGTools - http://gpgtools.org
>> Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
>>
>> iEYEAREIAAYFAlEto8oACgkQ9CaO5/Lv0PDX8gCfVG46d8YDTpKxEXEtqik1E17x
>> w60AoKrQ8yOuSfsZ23lcKLsBLxk1igwW
>> =P8HP
>> -----END PGP SIGNATURE-----
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>

Re: Issue with Async Servlet onTimeout

Posted by Sumit Bhardwaj <su...@gmail.com>.
Sure Chris,

would try with 7.0.37

Thanks,
Sumit

On Wed, Feb 27, 2013 at 11:42 AM, Christopher Schultz <
chris@christopherschultz.net> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA256
>
> Sunit,
>
> On 2/26/13 8:05 PM, Sumit Bhardwaj wrote:
> > Hi,
> >
> > I am using AsyncContext for implementing a file download app and
> > seeing issues on the timeout. I am using tomcat 7.0.23  (and have
> > tried on 7.0.28 as well, but seeing the issue in 28 as well)
>
> Any chance of testing on 7.0.37, the current release? There have been
> a number of fixes to the async portions of Tomcat since 7.0.23/28,
> though none of the changelog descriptions jump out at me as being
> obviously relevant.
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
> Comment: GPGTools - http://gpgtools.org
> Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
>
> iEYEAREIAAYFAlEto8oACgkQ9CaO5/Lv0PDX8gCfVG46d8YDTpKxEXEtqik1E17x
> w60AoKrQ8yOuSfsZ23lcKLsBLxk1igwW
> =P8HP
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: Issue with Async Servlet onTimeout

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Sunit,

On 2/26/13 8:05 PM, Sumit Bhardwaj wrote:
> Hi,
> 
> I am using AsyncContext for implementing a file download app and
> seeing issues on the timeout. I am using tomcat 7.0.23  (and have
> tried on 7.0.28 as well, but seeing the issue in 28 as well)

Any chance of testing on 7.0.37, the current release? There have been
a number of fixes to the async portions of Tomcat since 7.0.23/28,
though none of the changelog descriptions jump out at me as being
obviously relevant.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEAREIAAYFAlEto8oACgkQ9CaO5/Lv0PDX8gCfVG46d8YDTpKxEXEtqik1E17x
w60AoKrQ8yOuSfsZ23lcKLsBLxk1igwW
=P8HP
-----END PGP SIGNATURE-----

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