Recent

Author Topic: A problem caused this program to stop interacting with Windows.  (Read 13929 times)

powerpcer

  • Full Member
  • ***
  • Posts: 100
from windows reporting, i got this
FriendlyEventName=Stopped responding and was closed
ConsentKey=AppHangXProcB1
AppName=CodaMina Telnet
ReportDescription=A problem caused this program to stop interacting with Windows.
NsPartner=windows
NsGroup=windows8
ApplicationIdentity=7A1FB9867FA98CFACA1A967D8FF0A046
MetadataHash=1236236481

for my APPLICATION is a thread program, when i close the main form, i will close all thread and then exit.
i am sure the procedure.execute  was quit, but sometime not all time, Application hang-up and show above message up in Windows Event Log.
and also shows me:cross-thread deadlock.

any suggestion for me?

the debug screen on LAZARUS
« Last Edit: August 10, 2021, 11:13:05 am by powerpcer »

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: A problem caused this program to stop interacting with Windows.
« Reply #1 on: August 10, 2021, 09:36:04 am »
any suggestion for me?
Show your code, programmers don't use crystal balls.

powerpcer

  • Full Member
  • ***
  • Posts: 100
Re: A problem caused this program to stop interacting with Windows.
« Reply #2 on: August 10, 2021, 11:16:39 am »
Code: Pascal  [Select][+][-]
  1. procedure TCPClientThread.Execute;
  2. var
  3.   ustart,uend:Uint32;
  4.   res:integer;
  5.         timeval:TTimeVal;
  6.         BufRev:pbyte;//buffer
  7. begin
  8.   //ustart:=MilliSecondOfTheday(now);
  9.   BufRev:=allocmem(BUFSIZE);
  10.   timeval.tv_sec:=timeouts*1000;
  11.   timeval.tv_usec:=50;
  12.   //res:=setsockopt(skt,SOL_SOCKET,SO_RCVTIMEO,@timeval,sizeof(timeval));
  13.   while Terminated=false do
  14.         begin
  15.           if skt=-1 then
  16.                 begin
  17.                 isWaiting:=true;
  18.                         if Terminated then
  19.                           continue;
  20.                         logmsg('start Waiting..');
  21.       mEvent.WaitFor(INFINITE);
  22.       mEvent.ResetEvent;
  23.                         logmsg('start check Terminated..');
  24.                         if Terminated then
  25.                           continue;
  26.       logmsg('start working..');
  27.                         if skt=-1 then
  28.                         begin
  29.         res:=ConnectTo(serverhost,serverport,5);
  30.                         if res<0 then
  31.                         begin
  32.           logmsg('connect fail..');
  33.                           Event(4,0,nil);
  34.                           continue;
  35.                         end;
  36.                         end;
  37.                         isWaiting:=false;
  38.                         Event(1,0,nil);
  39.                 end;
  40.           while  (skt>0)   do
  41.     begin
  42.                 res:=recv(skt,BufRev[0],BUFSIZE,0);
  43.                 if (res>0) then
  44.                 begin
  45.                         Event(3,res,@BufRev[0]);
  46.                 end
  47.                 else
  48.                         if (res<=0) then
  49.                 begin
  50.                                 Event(2,res,@BufRev[0]);
  51.                                 disconnect();
  52.                         break;
  53.                 end;
  54.                 end;
  55.   end;//end while true
  56.   logmsg('Terminated..');
  57. end;
  58.  
Code: Pascal  [Select][+][-]
  1. procedure Tmainfrm.FormClose(Sender: TObject; var CloseAction: TCloseAction);
  2. begin
  3.   l:=telnet.loopforward();
  4.   i:=telnet.getCount();
  5.   while l<>nil do
  6.   begin
  7.        l^.t.Free;
  8.        sleep(50);
  9.  
  10.        Dispose(l^.r);
  11.        Dispose(l);
  12.        l:=telnet.loopforward();
  13.   end;
  14.   telnet.Free;
  15. end;
  16.  
all code are reach the end.
« Last Edit: August 10, 2021, 12:14:27 pm by powerpcer »

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: A problem caused this program to stop interacting with Windows.
« Reply #3 on: August 11, 2021, 12:13:36 am »
The formatting is confusing me %)

I see a line like mEvent.WaitFor(INFINITE)
You don't seem to call Terminate and WaitFor

I would expect each thread to decrease a common counter like in OnTerminte event
It should help you know which thread if any

powerpcer

  • Full Member
  • ***
  • Posts: 100
Re: A problem caused this program to stop interacting with Windows.
« Reply #4 on: August 11, 2021, 03:26:06 am »
l^.t.Free; will call mEvent.setevent to make thread wake-up from mEvent.WaitFor(INFINITE).
this can be approve by i got message from logmsg('Terminated..');

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: A problem caused this program to stop interacting with Windows.
« Reply #5 on: August 11, 2021, 03:36:44 am »
That doesn't answer the other possibilities, like connectTo and Recv. Also, Terminated is not changed in your posted code.

powerpcer

  • Full Member
  • ***
  • Posts: 100
Re: A problem caused this program to stop interacting with Windows.
« Reply #6 on: August 11, 2021, 04:35:18 am »
as i said, my code in single thread,  i am sure that it reach logmsg('Terminated..');
so i cannot get your point: Terminated is not changed in your posted code.


engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: A problem caused this program to stop interacting with Windows.
« Reply #7 on: August 11, 2021, 05:27:59 am »
Do you call Terminate directly or indirectly? If not, how would Terminated become TRUE?

powerpcer

  • Full Member
  • ***
  • Posts: 100
Re: A problem caused this program to stop interacting with Windows.
« Reply #8 on: August 11, 2021, 08:06:49 am »
call Terminate directly when .free was called.

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: A problem caused this program to stop interacting with Windows.
« Reply #9 on: August 11, 2021, 03:32:41 pm »
OK, I'll assume it has nothing to do with threads.


Does it pass after Application.Run?
If not, try reversing the value in Application.CaptureExceptions and see if it hangs.

If you have finalization sections in your units, double check the code there and log its end

Run without optimization, and of course enable all the checks.


powerpcer

  • Full Member
  • ***
  • Posts: 100
Re: A problem caused this program to stop interacting with Windows.
« Reply #10 on: August 12, 2021, 04:02:11 am »
after add TAPPLICATION EXCEPTION CATCHER,
i saw CLPED25519_%$$_finalize_implicit$,
but in CLPED25519 doesnt have finalization area. what's wrong?

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: A problem caused this program to stop interacting with Windows.
« Reply #11 on: August 12, 2021, 04:26:34 am »
If you have managed types, like a String, as a global variable in a unit for instance, then it needs to be freed. The compiler adds a hidden finalization section with the proper code.

powerpcer

  • Full Member
  • ***
  • Posts: 100
Re: A problem caused this program to stop interacting with Windows.
« Reply #12 on: August 12, 2021, 04:35:06 am »
so, oh, how to solve? that not handle by my code, anyway to indicate?

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: A problem caused this program to stop interacting with Windows.
« Reply #13 on: August 12, 2021, 06:16:28 am »
Try to remove the global variables in that unit. It sounds like you might be damaging the memory related to these variables?

powerpcer

  • Full Member
  • ***
  • Posts: 100
Re: A problem caused this program to stop interacting with Windows.
« Reply #14 on: August 12, 2021, 07:17:10 am »
there are no global variable in that unit file, only resourcestring area has 2 items relate to string.

 

TinyPortal © 2005-2018