🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.socket
Article #1985

Re: help with Indy Telnet

#1985
From: Andre' Burke
Date: Fri, 01 Sep 2006 08:28
87 lines
4281 bytes
Hi Remy,

I agree with everything you have said.
What I can't figure out is why the OnDataAvailable would deadlock, or for 
that matter the thread that is calling it.

The very first thing I do on entering the OnDataAvailable method is to log a 
message to the log file.
When this happens, I dont even get this message in the log-file, so its not 
even getting into the code of the OnDataEvent.
So it seems its not something in my code in the OnDataEvent.
The logging code has a single critical section which is only locked when the 
actualy writing to the file takes place so as to
prevent threading issues when writing to the log.
This same code is used in a number of other projects and has never caused 
any issues so I dont think its that either.


This one has me totally floored.


Andre'






"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message 
news:44f7e8a0$1@newsgroups.borland.com...
>
> "Andre' Burke" <no.spam@spam.no> wrote in message
> news:44f7d1ac$1@newsgroups.borland.com...
>
>> I can then see it going into the MyDisconnect function and calling
>> the disconnect. I write a log message right before and directly after
>> the actual diconnect call and the log file shows the one before it
>> and nothing after that.
>
> In order for that to happen, the TIdTelnet's internal reading thread would
> have to be deadlocked.  Under normal situations, disconnecting the socket
> would terminate the thread immediately, but if the thread is blocked then 
> it
> would not be able to detect the socket being closed, which would in turn
> block Disconnect() because it waits for the thread to terminate before 
> then
> exiting.
>
>> In fact I have added another timer to the form that simply fires once
>> a second and writes the state of the original timer to the log file, eg
>> whether it is enabled or not.
>> Even this extra timer stops at this point.
>
> Sounds like you are deadlocking the main thread as well, since TTimer is a
> message-based timer.  If you are calling Disconnect() in the context of 
> the
> main thread, as the internal reading thread is blocked so that it cannot
> terminate itself, then Disconnect() is going to be blocked, and thus 
> prevent
> the main thread from processing pending messages.
>
>> I originally had a similar problem when I tried to disconnect from
>> inside the OnDataAvailable event.
>
> You cannot do that.  That is a guaranteed deadlock, since Disconnect() 
> would
> be waiting on the thread to terminate, but the thread would be waiting for
> Disconnect() to exit.
>
>> This seems to be something similar, except that the disconnect
>> is now no longer being called in the OnDataAvailable method
>> but rather in the timer.
>
> That does not negate the possibility of the reading thread still becoming
> deadlocked.
>
>> It seems as if the Telnet component recieves the incoming data, but
>> for some reason gets stuck and doesnt call the OnDataAvailable
>> method.
>
> That cannot happen.  What is more likely the case is that the
> OnDataAvailable event handler is becoming deadlocked.
>
>
> Gambit
>
> 
Technical Details
Message-ID: <44f7ef1a@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newshub.sdsu.edu!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <44f68cef@newsgroups.borland.com> <44f6917c$1@newsgroups.borland.com> <44f69c27@newsgroups.borland.com> <adsdf2dk8k4s0tefv5r49fi67ghjs6rlmt@4ax.com> <44f7d1ac$1@newsgroups.borland.com> <44f7e8a0$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,3d66693bd859a203
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Andre' Burke" <no.spam@spam.no>
Newsgroups: borland.public.cppbuilder.internet.socket
References: <44f68cef@newsgroups.borland.com> <44f6917c$1@newsgroups.borland.com> <44f69c27@newsgroups.borland.com> <adsdf2dk8k4s0tefv5r49fi67ghjs6rlmt@4ax.com> <44f7d1ac$1@newsgroups.borland.com> <44f7e8a0$1@newsgroups.borland.com>
Subject: Re: help with Indy Telnet
Date: Fri, 1 Sep 2006 10:28:03 +0200
Lines: 89
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 196.38.124.67
Message-ID: <44f7ef1a@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1157099290 196.38.124.67 (1 Sep 2006 01:28:10 -0700)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newshub.sdsu.edu!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail