"Connection closed gracefully" problem

Hi,

I have two Delphi applications, which communicate with Indy / Http. 

The client runs in a loop and sends several hundred times a request to
the server. Requests are sent one by one (all from the same thread).

Sometimes the server app needs up to one minute to prepare the
response (time in OnCommandGet event).

In this case (at least I think so), the client gets a "Connection
closed gracefully" exception.

If I run the server app in the debugger and stop it in the
OnCommandGet event, I can stop it for 2-3 minutes. 
In this case, the client app is just blocked and resumes with no
problem, once I continue the server application.

So I think at some point the TIdHttpServer just discards a long
running request thread and sends an error back to the client.

Is this correct?

How can I ensure that a request is not closed, even if it takes a long
time to complete it?

I found the TerminateWaitTime property but noticed, that this is never
used in the Indy code.

I'm using Delphi XE2 prof. with preinstalled Indy.

cu Christian
0
Christian
5/23/2012 6:54:19 AM
embarcadero.delphi.winsock 1874 articles. 2 followers. Follow

5 Replies
5590 Views

Similar Articles

[PageSpeed] 6

Christian wrote:

> In this case (at least I think so), the client gets a "Connection
> closed gracefully" exception.

That means the connection is being intentionally and gracefully closed on 
the other end.  By default, Indy uses infinite timeouts and no TCP/IP keepalives. 
 If the server itself is not closing the connection, but the connection passes 
through a network router to reach the server, the router may be closing the 
connection if it is idle for too long.

> So I think at some point the TIdHttpServer just discards a long
> running request thread and sends an error back to the client.

No, it does not.

> How can I ensure that a request is not closed, even if it takes a long
> time to complete it?

I would suggest enabling TCP/IP keepalives to see if it makes a difference. 
 Since TIdHTTP uses dynamic connections and thus may have to re-connect between 
requests, you will have to use its OnConnected event to re-enable the keepalive 
on each new connection, eg:

{code}
procedure TForm1.IdHTTP1Connected(ASender: TObject);
begin
  // send a keepalive every 1s after 15s of being idle...
  IdHTTP1.Socket.Binding.SetKeepAliveValues(True, 15000, 1000);
end;
{code}

> I found the TerminateWaitTime property but noticed, that this is never
> used in the Indy code.

That is used only during server shutdown, but is currently disabled.  When 
it was enabled, it specified the timeout used when waiting for client threads 
to terminate.

--
Remy Lebeau (TeamB)
0
Remy
3/5/2013 6:24:15 PM
>That means the connection is being intentionally and gracefully closed on 
>the other end.  By default, Indy uses infinite timeouts and no TCP/IP keepalives. 
> If the server itself is not closing the connection, but the connection passes 
>through a network router to reach the server, the router may be closing the 
>connection if it is idle for too long.

OK. But why does it happen when the server app is running and a
request has a long timeout, but it doesn't happen if I cause the long
timeout with a debugger breakpoint in the thread?

> I would suggest enabling TCP/IP keepalives to see if it makes a difference. 
I added SetKeepAliveValues(). So far my first tests show, that it
seems to help.

Thanks.

cu Christian
0
Christian
3/5/2013 7:51:55 PM
Christian wrote:

> OK. But why does it happen when the server app is running and a
> request has a long timeout, but it doesn't happen if I cause the
> long timeout with a debugger breakpoint in the thread?

The particular error you are seeing is caused by the other party disconnecting. 
 Since it only happens when TIdHTTPServer is not frozen by the debugger, 
the only possibility that makes sense is that the long-running thread is 
encountering an uncaught exception (verify that with the server's OnException 
event).  If TIdHTTPServer catches an uncaught exception, it will close the 
socket.  TIdHTTPServer itself does not close long-running threads in general.

--
Remy Lebeau (TeamB)
0
Remy
3/5/2013 8:28:39 PM
> Since it only happens when TIdHTTPServer is not frozen by the debugger, 
>the only possibility that makes sense is that the long-running thread is 
>encountering an uncaught exception (verify that with the server's OnException 

In my HandleRequest event I have a try except block. So I hardly can
imagine, that an uncaught exception can happen. But I wil  verify
that.

cu Christian
0
Christian
3/5/2013 9:06:44 PM
Christian wrote:

> In my HandleRequest event I have a try except block.

Make sure you are not throwing away any Indy-specific exceptions.  If you 
catch an EIdException-derived exception, you should re-raise it after you 
have processed it.  This is important for TIdHTTPServer to detect client-side 
disconnects in particularly, especially during server shutdown if clients 
are still connected.

--
Remy Lebeau (TeamB)
0
Remy
3/5/2013 11:05:05 PM
Reply:

Similar Artilces:

"Connection closed gracefully" on computers where Delphi is not installed
Hello dear programmers, I am experiencing a problem with an email client application I made using indy TIdSMTP: I didn't experience problems on development computers, where there's Delphi installed. On other computers, while sending mail I get this exception: "Connection closed gracefully" and email is not sent. Maybe I should include some package? Thanks in advance. <Flavio Foglia> wrote in message news:297116@forums.embarcadero.com... > I am experiencing a problem with an email client application I made using > indy TIdSMTP: Which versions of...

When is "close" not really "close"
I've had a strange thing occur a couple of times. When I leave at night, I leave my computer on, but close Thunderbird. That way, I can VPN in from home and view the mail store, but still access e-mail through POP3. One night, a week or so ago, I checked POP3 from home and noticed the mailbox was empty. That's impossible; I get about 500 messages a day. So, I took control of my desktop session and looked around. Thunderbird was not visible, but it was still running in the background. I have since determined that if I close it with the "X" icon at upper ...

"Connection closed gracefully" errors
I am using the TIdHTTP component from Indy 10.5.1 with Delphi 2007. Occasionally my app will be working away and I will get a "Connection closed gracefully" exception during the Post method for no apparent reason. That is, there are no other errors reported. Once, this error is reported, all subsequent attempts to Post will return the same error. The only way to get the application running again is to shut it down and restart it. BTW, I always call the Close method after each Post, successful or not. How can I recover from this error condition? "Stephen B...

Problem with "isc_service_query" and "isc_info_svc_get_license" +"isc_info_svc_get_licensed_users"
I have problem with getting a correct result from "isc_service_query" when I pass "3A" (Get license and licensed_users), in fact I get an "Unexpected Output buffer value" error when IBX tries to read the license information from the result. From the debugging I have done it seems like I dont get the correct result from Interbase. Looking at the result I see that I get a correct value on "isc_info_svc_get_licensed_users", but the rest of the buffer is filled with zeros where I expect to see 0x33 and information about licenses. I am using...

"submit" to Access DB returns "connection closed"error
The error when I submit data  is as follows: Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidOperationException: ExecuteNonQuery requires an open and available Connection. The connection's current state is closed.Source Error: Line 17: Dim comDatabase As New System.Data.OleDb.OleDbCommand(strSQL, conDatabase) Line 18: Line 19: comDatabase.ExecuteNonQuery() Line 20:...

.ALLCOL("%COLUMN%", " ", ", ", ", ")
Do you know anyway for me to exclude a subset of columns returned by this function. We have two columns (rec_user and rec_datetime) which are in all of our tables, but when generating triggers I want automatically generate a script which does not include those two columns but does include all other columns in that table. Bruce I should add that I am using PD 9.0.0.580. Bruce "Bruce Lamb" <lamb.bruce@mayo.edu> wrote in message news:6HgI315nCHA.155@forums.sybase.com... > Do you know anyway for me to exclude a subset of columns returned by this > function. ...

Precedence of "where" ("of", "is", "will")?
Nobody on #perl6 today could answer this one. Is: Str | Int where { $_ } the same as: (Str | Int) where { $_ } or: Str | (Int where { $_ }) ? Followup questions, Mr. President: What kind of operators are "where", "of", "is", and "will"? Is there a reason that S03 doesn't list them? What are their precedence(s)? -- Chip Salzenberg - a.k.a. - <chip@pobox.com> Open Source is not an excuse to write fun code then leave the actual work to others. Chip Salzenberg writes: &...

TIdHTTP.Head --> "Connection Closed Gracefully"?
Thanks to help from this group, I'm making progress on using the TIdHTTP.Head call to determine if a file exists, but it's slow sloggin'!!! I've found that some (but not all) servers politely give you you a "404" response code when testing for a file known not to exist. Google is one one the good guys: Calling TIdHTTP.Head for this address http://www.google.com/goofypage.html produces an exception, with this message: HTTP/1.1 404 Not Found That makes Google a good place to see if my methods are working. So, I make three call...

WISH: Undo for "Close All Tabs" or "Close Other Tabs"
It seems that I often mess up and click "close other tabs" or "close all tabs" when I mean to click "Close this tab" Is there anyway we could have a fast undo for this mistake? Thanks On 24/07/2003 12:10, Brian King wrote: > It seems that I often mess up and click "close other tabs" or "close all > tabs" when I mean to click "Close this tab" > > Is there anyway we could have a fast undo for this mistake? Thanks http://multizilla.mozdev.org has this capability. If you right-click on the bar that the ...

"Close Other Tabs" "bug"
[from: http://forums.mozillazine.org/viewtopic.php?t=69338] Ugh!!!, fricken, it just happened to me *again* writing this damn post!!! ARGH!!!! ok, now i'm rewriting this post for the exact reason i'm posting. the singular most frustrating and repeated experience i have with firefox/mozilla is accidentally selecting the "Close Other Tabs" when i intended to select "Close Tab". i would like a confirmation dialog to appear just as it does when i attempt to close a browser window with multiple tabs. i've searched many posts on the forums and have...

Problem With "FileUpload" and "UpdatePanel"
Hi, I Have a problem with FileUpload and UpdatePanel. when i use an Update Panel in a page, Control "FileUpload" Doesn't Work Correctly. but when i remove UpdatePanel, Problem will Resolve. UpdatePanel Placed in MasterPage, so i can't remove it, cause i'll should Place an UpdatePanel in each Page. It's almost impossible. and, FileUpload is placed in a FormView.when I click on "Upload" Button (that I Created for Upload selected  file) , Selected File will remove and file will not Upload. So, now what i have to do? is it possible to Use both "...

Why "Stealth" is better than "Closed"...
Your comments, suggestions are very welcome to strengthen the explanation.. Why "Stealth" is better than "Closed"... There has been an on-going thread in grc.shieldsup about the relative merits of "Stealthing" ports. Some folks here argue the point that a "Closed" port is just as secure as a "Stealthed" port. I've been arguing that "Stealth" is better than "Closed", and I've now put together what I think is a comprehensive explanation as to why that is. I argue that the vast majority of visitors t...

quotes, quotes, quotes...
I am getting this error and I know what is causing it, but I have no idea how to fix it, any help would be great. The script steps through the /var/log/messages file on a linux server and puts The entries into a mysql database. However when it gets to the 'hlt' line in the messages file it just barfs. The single quotes are freaking it out. I know about quotes but not how to use in this situation. Thanks, Paul Error: May 27 17:53:00 localhost kernel: Checking 'hlt' instruction... OK. <----- doesn't like this in the messages file DBD::mysql::st exec...

suggestion: "Close Tabs to the Left", "Close Tabs to the Right"
I would find it useful if in addition to the "Close Other Tabs" command, there were a way to "Close Tabs to the Left" and "Close Tabs to the Right" when you right-click on a particular tab. Particularly when I've exhausted a train of thought that might consist of a number of tabs, it'd be nice to be able to just close all tabs to the right of the last tab before that train of thought. This may be peculiar to the way I abuse tabs but I'm just throwing it out there in case I'm not alone. ...

Web resources about - "Connection closed gracefully" problem - embarcadero.delphi.winsock

Resources last updated: 11/21/2015 12:54:00 PM