tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Filip Hanik - Dev Lists <devli...@hanik.com>
Subject Re: how to close a comet request outside of an event?
Date Thu, 26 Apr 2007 16:26:28 GMT
Correct, an asynchronous close doesn't go all the way down to the IO 
layer, it just marks the request closed.
remember event.close doesn't mean TCP.socket.close, it means that this 
event/request sequence is done

There are still many enhancements to be done to the Comet API, such as 
non blocking reads/writes and others, feel free to gather up your 
thoughts in a bulleted type email instead of the essays, they are a 
little hard to read :)

Filip

Sebastiaan van Erk wrote:
> Hi,
>
> The reason I get the exceptions on the Tomcat server side seems to be 
> because I close the socket on the client at the same time I try to 
> close it on the server, causing two unsynchronized closes on the 
> OutputStream. I don't really know what to synchronize on though, since 
> I don't have an event (the close is done as a result of a server side 
> event and not a Comet event); the other close is done deep inside of 
> Tomcat. The only thing that the two have in common could be the 
> request itself or the outputstream, but I don't know if Tomcat does 
> any synchronization on these objects.
>
> One way to avoid this simultaneous close would seem to be this: my 
> server application calls close on the OutputStream of the response, my 
> client application reads the EOF (-1) and then closes the socket, 
> causing an END event on the server side, in which I do any necessary 
> cleanup actions.
>
> The problem is, when I try this approach, it takes my client many 
> seconds (>30) to receive the EOF, instead of getting it immediately. 
> That is why I was wondering what the correct way is to end a 
> request/response outside of a Comet event (as a result of an 
> application event). Even better would be if I could somehow trigger 
> the END event on the server to finish the request and close the 
> socket, so I don't have to rely on the client to play nice.
>
> BTW, I'm using the subversion version of tomcat, synched with 
> subversion late yesterday evening.
>
> Regards,
> Sebastiaan
>
> Praveen Balaji wrote:
>> I see the same problem with my client too. However, I don't see the
>> issue when I use a client using Jakarta HTTP client. I'm still looking
>> into this. Any help will, of course be welcome and delightfully
>> devoured.
>>
>>
>> This is not really the same bug report, but something to think about
>> when you're working with events. Also, it may have a clue I'm missing.
>>
>> http://issues.apache.org/bugzilla/show_bug.cgi?id=42198
>>
>> Also, check with the trunk to make sure you're able to reproduce your
>> defect.
>>
>> Praveen
>>
>> -----Original Message-----
>> From: Sebastiaan van Erk [mailto:sebster@sebster.com] Sent: Thursday, 
>> April 26, 2007 2:07 PM
>> To: Tomcat Users List
>> Subject: how to close a comet request outside of an event?
>>
>> Hi,
>>
>> I the following Comet question; due to a server event (not a comet 
>> event), I want to write some data to a client request and finish the 
>> request. Currently I write the data and then call 
>> OutputStream.close() on the response output stream. This seems to 
>> work, except that it takes a long time before I get an END event for 
>> that request. On the client this causes the EOF to the request input 
>> stream to arrive very late. This is a problem, because both the 
>> server and client are handling so many requests that I run out of 
>> file descriptors and get the following exception (on the server):
>>
>> Apr 26, 2007 10:28:23 AM org.apache.tomcat.util.net.NioEndpoint$Acceptor
>> run
>> SEVERE: Socket accept failed
>> java.io.IOException: Too many open files
>>     at sun.nio.ch.ServerSocketChannelImpl.accept0(Native Method)
>>     at 
>> sun.nio.ch.ServerSocketChannelImpl.accept(ServerSocketChannelImpl.java:1
>> 45)
>>     at 
>> org.apache.tomcat.util.net.NioEndpoint$Acceptor.run(NioEndpoint.java:117
>> 7)
>>     at java.lang.Thread.run(Thread.java:619)
>>
>> Note: I'm running the client and server on the same machine, but the 
>> client does not get any "Too many open files" exceptions (it does not 
>> get any exceptions at all), so I'm assuming the process limit of 
>> tomcat is reached, suggesting that tomcat is not closing the request 
>> sockets until the END event...
>>
>> If I close the request on the client side before I get the EOF (-1) in a
>>
>> read I don't get the Too many open files problem and generally get 
>> the END event immediately on the server side, but I sporadically get 
>> NullPointerExceptions and AsynchronousCloseExceptions and 
>> ClosedChannelExceptions on the server side in the 
>> OutputStream.close() method. I figure the proper method is for the 
>> client tp wait for the server to say "the request is done" (by 
>> waiting for the EOF) before closing thesocket, but how do I make sure 
>> it gets closed immediately on the server side if I'm not in a comet 
>> event?
>>
>> Regards,
>> Sebastiaan
>>
>> ---------------------------------------------------------------------
>> To start a new topic, e-mail: users@tomcat.apache.org
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>> ---------------------------------------------------------------------
>> To start a new topic, e-mail: users@tomcat.apache.org
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>   
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
>


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


Mime
View raw message