A problem caused this program to stop interacting with Windows. lazarus / 34-Windows ---------------------------------------------------------------------- powerpcer · 2021-08-10 02:34 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 ---------------------------------------------------------------------- Leledumbo · 2021-08-10 07:36 Quote from: powerpcer on August 10, 2021, 04:34:02 amany suggestion for me? Show your code, programmers don't use crystal balls. ---------------------------------------------------------------------- powerpcer · 2021-08-10 09:16 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TCPClientThread.Execute;var  ustart,uend:Uint32;  res:integer;        timeval:TTimeVal;        BufRev:pbyte;//bufferbegin  //ustart:=MilliSecondOfTheday(now);  BufRev:=allocmem(BUFSIZE);  timeval.tv_sec:=timeouts*1000;  timeval.tv_usec:=50;  //res:=setsockop t(skt,SOL_SOCKET,SO_RCVTIMEO,@timeval,sizeof(timeval));  while Terminated=false do        begin          if skt=-1 then              begin                isWaiting:=true;                        if Terminated then                          continue;                      logmsg('start Waiting..');      mEvent.WaitFor(INFINITE);      mEvent.ResetEvent;                        logmsg('start check Terminated..');                        if Terminated then                        continue;      logmsg('start working..');                      if skt=-1 then                        begin        res:=ConnectTo(serverhost,serverport,5);                        if res<0 then                        begin          logmsg('connect fail..');                          Event(4,0,nil);                        continue;                        end;                        end;                        isWaiting:=false;                        Event(1,0,nil);                end;          while  (skt>0)   do    begin                res:=recv(skt,BufRev[0],BUFSIZE,0);              if (res>0) then                begin                        Event(3,res,@BufRev[0]);                end                else                      if (res<=0) then                begin                              Event(2,res,@BufRev[0]);                                disconnect();                        break;                end;              end;  end;//end while true  logmsg('Terminated..');end; Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure Tmainfrm.FormClose(Sender: TObject; var CloseAction: TCloseAction); begin  l:=telnet.loopforward();  i:=telnet.getCount();  while l<>nil do  begin       l^.t.Free;       sleep(50);        Dispose(l^.r);     Dispose(l);       l:=telnet.loopforward();  end;  telnet.Free;end; all code are reach the end. ---------------------------------------------------------------------- engkin · 2021-08-10 22:13 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 · 2021-08-11 01:26 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 · 2021-08-11 01:36 That doesn't answer the other possibilities, like connectTo and Recv. Also, Terminated is not changed in your posted code. ---------------------------------------------------------------------- powerpcer · 2021-08-11 02:35 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 · 2021-08-11 03:27 Do you call Terminate directly or indirectly? If not, how would Terminated become TRUE? ---------------------------------------------------------------------- powerpcer · 2021-08-11 06:06 call Terminate directly when .free was called. ---------------------------------------------------------------------- engkin · 2021-08-11 13:32 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 · 2021-08-12 02:02 after add TAPPLICATION EXCEPTION CATCHER, i saw CLPED25519_%$$_finalize_implicit$, but in CLPED25519 doesnt have finalization area. what's wrong? ---------------------------------------------------------------------- engkin · 2021-08-12 02:26 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 · 2021-08-12 02:35 so, oh, how to solve? that not handle by my code, anyway to indicate? ---------------------------------------------------------------------- engkin · 2021-08-12 04:16 Try to remove the global variables in that unit. It sounds like you might be damaging the memory related to these variables? ---------------------------------------------------------------------- powerpcer · 2021-08-12 05:17 there are no global variable in that unit file, only resourcestring area has 2 items relate to string. ---------------------------------------------------------------------- engkin · 2021-08-12 06:22 Compile with -al in the custom options and check the generated assembly file. ---------------------------------------------------------------------- powerpcer · 2021-08-12 09:02 after do more testing, there still has cross-thread deadlock happen, but this time, no exception was generated. still, it is not always happens. ---------------------------------------------------------------------- powerpcer · 2021-08-13 15:10 more testing, if remove the .free part of loop, application will close normally, but sometime has a thread that not terminated. living in background. a zombie process. ---------------------------------------------------------------------- powerpcer · 2021-08-24 00:16 i am trying to using windbg for hanging dump file, but it looks that FPC dbg file not fit into windbg, is there any converter that can do this? convert the symbol table of FPC to windbg need ---------------------------------------------------------------------- 440bx · 2021-08-24 09:50 Quote from: powerpcer on August 24, 2021, 02:16:20 am... it looks that FPC dbg file not fit into windbg, is there any converter that can do this? convert the symbol table of FPC to windbg need I'm not sure what I'm going to mention is what you're asking for but, just in case, FPC outputs debug information in DWARF format.  WinDbg uses MS' PDB format.  There is a utility named "cv2pdb" that converts from DWARF to PDB (google it, it's on github) cv2pdb works well on 64bit exes (produced by FPC), I haven't gotten it to work with 32bit exes.  Also, the conversion is good enough for someone who is comfortable with assembler because there is quite a bit of DWARF info that cv2pdb does not convert to PDB.  IOW, there is a fair amount of information lost, locals among other things but, in spite of that, the result is very usable. HTH. ---------------------------------------------------------------------- powerpcer · 2021-08-25 15:59 thanks, but i got XXX.dbg: no codeview debug entries found that download from  Npackd.org i had try to build from dwarf or dwarf2 ---------------------------------------------------------------------- powerpcer · 2021-08-25 23:00 ok, finally, i got the point, that's cannot use: external debug  info file ---------------------------------------------------------------------- powerpcer · 2021-09-17 15:14 after i reproduce, but not all the time, it most of time show me this when program hangup on clicking "close" icon on windows before i click close, if i move over minimize and/or maximize, left the window, and back to click close.  it shows me on windbg after i use !analyze -v -hang Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 00000000`013ff358 00007fff`0e3d379d : 00000000`013ff560 00007fff`0dfbeb96 00000000`00000014 00000000`00000001 : ntdll!ZwWaitForAlertByThreadId+0x1400000000`013ff360 00007fff`0e3d3652 : 00000000`00000000 00000000`00000000 00000000`013ff448 00000001`004dc148 : ntdll!RtlpWaitOnAddressWithTimeout+0x8100000000`013ff390 00007fff`0e3d346d : 00000001`004dc140 00000000`00001722 00000000`00000000 00007fff`0c24e1a0 : ntdll!RtlpWaitOnAddress+0xae00000000`013ff400 00007fff`0e39fcb4 : 00000000`0000000f 00000000`00000000 00000000`fffffffa 00007fff`0e152ccd : ntdll!RtlpWaitOnCriticalSection+0xfd00000000`013ff4e0 00007fff`0e39fae2 : 00000000`00000000 00000000`01645200 00000000`06439398 ffffffff`f0011bb1 : ntdll!RtlpEnterCriticalSectionContended+0x1c400000000`013ff540 00000001`0001341a : 00000000`013ff5b0 00000001`000c81bb ffffffff`ca01164a 00000000`00000000 : ntdll!RtlEnterCriticalSection+0x4200000000`013ff570 00000001`00012a6b : 00000000`0085000f ffffffff`f0011bb1 00000000`013ff6f0 00007fff`0e3c07b0 : CodaMinaTelnet!main+0x106fa00000000`013ff5a0 00000001`00011f39 : 00000000`0049414e 00000000`016183c0 00000000`013ff6f0 00000001`000f8c5d : CodaMinaTelnet!main+0xfd4b00000000`013ff5d0 00000001`00012049 : 00000000`00000000 ffffffff`f0011bb1 00004331`00000000 00000001`00000000 : CodaMinaTelnet!main+0xf21900000000`013ff610 00000001`00012173 : 00000001`00000000 00000001`00012eef 00000001`00000000 00000000`00000000 : CodaMinaTelnet!main+0xf32900000000`013ff650 00000001`000111eb : 00000000`000002d1 00000000`00000000 00000000`00000000 00000000`00000000 : CodaMinaTelnet!main+0xf45300000000`013ff6a0 00000001`00008fd9 : 00000000`00000001 00000001`00012eef 00000000`01669890 00000001`0016881b : CodaMinaTelnet!main+0xe4cb00000000`013ff6d0 00000001`0000fce8 : 00000000`00000000 00000000`80007811 00000000`013ff770 00000001`00168a89 : CodaMinaTelnet!main+0x62b900000000`013ff700 00000001`0000fb07 : ffffffff`ffffffff 00000000`01669890 00000000`00000000 00000000`00000000 : CodaMinaTelnet!main+0xcfc800000000`013ff740 00000001`0000fd8c : 00000000`01669890 00000001`001683d9 00000000`013ff869 00000000`01669890 : CodaMinaTelnet!main+0xcde700000000`013ff790 00000001`00168491 : 00000000`0000000f 00000001`000485c5 00004331`f08042ca 00000001`0001364a : CodaMinaTelnet!main+0xd06c00000000`013ff7d0 00000001`000481c4 : 00000000`00000011 00000000`80007811 00000000`013ff930 00000000`06439220 : CodaMinaTelnet!MAINTHREADWRITE+0xa1 [lazlogger.pas @ 242]00000000`013ff820 00000001`0004870a : 00000000`00000000 00000000`00000000 00000000`00000220 00000000`00000000 : CodaMinaTelnet!FPCADDS_$$_init$+0x8ef400000000`013ff850 00000001`000fc010 : 00000000`0000000f 00000000`00000000 00000000`013ff930 00000001`00011192 : CodaMinaTelnet!FPCADDS_$$_init$+0x943a00000000`013ff8c0 00000001`000fdc67 : 00000001`001d8af0 00000000`00000001 00000000`00000048 00007fff`00000001 : CodaMinaTelnet!DOWINDOWPROC+0x6c0 [win32\win32callback.inc @ 1993]00000000`013ff9b0 00007fff`0dfbe858 : 00000000`00000000 00000000`00000001 00000000`00000001 00000000`00000000 : CodaMinaTelnet!WINDOWPROC+0x77 [win32\win32callback.inc @ 2676]00000000`013ffa10 00007fff`0dfbe299 : 00000000`00000000 00000001`000fdbf0 00000000`00150cd4 00000000`00000000 : user32!UserCallWinProcCheckWow+0x2f800000000`013ffba0 00000001`000fed8e : 00000001`000fdbf0 00000000`00000000 00000000`013ffef0 00000000`013ffef0 : user32!DispatchMessageWorker+0x24900000000`013ffc20 00000001`0002acf7 : 00000000`013ffda0 00000000`016183c0 00000000`016183c0 00000000`015e5a01 : CodaMinaTelnet!APPPROCESSMESSAGES+0xfe [win32\win32object.inc @ 399]00000000`013ffd40 00000001`0002b1e7 : 00000000`00000000 00000000`0161ae60 00000000`016183c0 00000000`016183c0 : CodaMinaTelnet!HANDLEMESSAGE+0x27 [include\application.inc @ 1281]00000000`013ffd80 00000001`00037e18 : 00000000`00000001 00000000`0161ae60 00000000`015e5a60 00000000`0161ae60 : CodaMinaTelnet!RUNLOOP+0x27 [include\application.inc @ 1416]00000000`013ffdc0 00000001`0002b1b6 : 00000000`013ffe70 00000001`000107dc 00000000`0161ae60 00000001`00000000 : CodaMinaTelnet!APPRUN+0x28 [include\interfacebase.inc @ 55]00000000`013ffe00 00000001`00002d9a : 00000000`00000000 00000000`00000000 00000000`00000000 00000001`00003635 : CodaMinaTelnet!RUN+0x66 [include\application.inc @ 1406]00000000`013ffe50 00000001`00002db6 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : CodaMinaTelnet!main+0x7a [CodaMinaTelnet.lpr @ 21]00000000`013ffe80 00000001`000170d0 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : CodaMinaTelnet!main+0x9600000000`013ffeb0 00000001`00002d17 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : CodaMinaTelnet!main+0x143b000000000`013fff00 00007fff`0c757034 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : CodaMinaTelnet!public_all+0x1d1700000000`013fff30 00007fff`0e3c2651 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : kernel32!BaseThreadInitThunk+0x1400000000`013fff60 00000000`00000000 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!RtlUserThreadStart+0x21 ---------------------------------------------------------------------- 440bx · 2021-09-17 16:18 Quote from: powerpcer on September 17, 2021, 05:14:54 pmafter i reproduce, but not all the time, it most of time show me this when program hangup on clicking "close" icon on windows before i click close, if i move over minimize and/or maximize, left the window, and back to click close.  it shows me on windbg after i use !analyze -v -hang Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 00000000`013ff358 00007fff`0e3d379d : 00000000`013ff560 00007fff`0dfbeb96 00000000`00000014 00000000`00000001 : ntdll!ZwWaitForAlertByThreadId+0x1400000000`013ff360 00007fff`0e3d3652 : 00000000`00000000 00000000`00000000 00000000`013ff448 00000001`004dc148 : ntdll!RtlpWaitOnAddressWithTimeout+0x8100000000`013ff390 00007fff`0e3d346d : 00000001`004dc140 00000000`00001722 00000000`00000000 00007fff`0c24e1a0 : ntdll!RtlpWaitOnAddress+0xae00000000`013ff400 00007fff`0e39fcb4 : 00000000`0000000f 00000000`00000000 00000000`fffffffa 00007fff`0e152ccd : ntdll!RtlpWaitOnCriticalSection+0xfd00000000`013ff4e0 00007fff`0e39fae2 : 00000000`00000000 00000000`01645200 00000000`06439398 ffffffff`f0011bb1 : ntdll!RtlpEnterCriticalSectionContended+0x1c400000000`013ff540 00000001`0001341a : 00000000`013ff5b0 00000001`000c81bb ffffffff`ca01164a 00000000`00000000 : ntdll!RtlEnterCriticalSection+0x42 Based on the output you posted, the first thought is that the hang is caused by waits which cannot be satisfied (e.g, a deadlock.) Based on that, I'd run the program under an apispy (there is a good one at rohitab), trap all apis that wait on something and inspect what is waiting on what when the wm_close message is generated. Another way of finding out if there may be a deadlock would be using Process Hacker and/or Process Explorer.  In that case, once the program is hung - don't terminate it, instead inspect its threads in Hacker/Explorer, if there is a deadlock, under "threads" you'll see two or more threads waiting for something (most likely each other in some way.) HTH. ---------------------------------------------------------------------- powerpcer · 2021-09-18 00:27 from windbg, i get locks below. my program is multithread 1 main UI thread, 1 socket thread, if let the thread terminated,will cause this, dead lock, if not. everything goes normal. socket thread has a Event object that use by thread itself. from my point is that "CodaMinaTelnet!EXCEPTIONOCCURRED+0x262 [forms.pp @ 1927] CodaMinaTelnet!main+0x14b9d " what cause this exception? any tools can help? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 0:000> !locks *** WARNING: Unable to verify timestamp for CodaMinaTelnet.exeCritSec CodaMinaTelnet!MURMURHASH3_X86_32 (CodaMinaTelnet+0x4dc140)+0 at 00000001004dc140WaiterWoken        NoLockCount          1RecursionCount     1OwningThread       19e4EntryCount         0ContentionCount    1*** Locked Scanned 13 critical sections0:000> ~.  0  Id: 154c.4638 Suspend: 0 Teb: 00000000`002b2000 Unfrozen   1  Id: 154c.19e4 Suspend: 0 Teb: 00000000`002ba000 Unfrozen   2  Id: 154c.4d88 Suspend: 0 Teb: 00000000`002bc000 Unfrozen0:000> ~1 kvChild-SP          RetAddr         : Args to Child                                                         : Call Site00000000`094e9e98 00000001`000ff28e : 00000000`016183c0 00000000`016183c0 00000000`016183c0 00000000`016183c0 : win32u!ZwUserShowWindow+0x1400000000`094e9ea0 00000001`0002a0ae : 00000000`00000000 00000001`0001364a 00000000`015dd1a0 00000000`016183c0 : CodaMinaTelnet!APPSETVISIBLE+0x5e00000000`094e9ee0 00000001`0001f03e : 00000000`094eaf70 00000000`094efeb0 00000000`00000001 00000000`094ebb30 : CodaMinaTelnet!UPDATEVISIBLE+0x2e [include\application.inc @ 991]00000000`094e9f20 00000001`000237b3 : 00000000`00000062 00000000`094ebb30 00000000`0161ae60 00000000`016183c0 : CodaMinaTelnet!SETVISIBLE+0x7e00000000`094e9f60 00000001`0001e34e : 00000000`0161ae60 00000001`0000e286 00004331`f8f12afa 00000000`0000001d : CodaMinaTelnet!HIDE+0x2300000000`094e9fa0 00000001`0001e3ca : 00000000`00000000 00000001`00042604 00000000`094ea030 00007fff`0bd024bd : CodaMinaTelnet!BEFOREDESTRUCTION+0x5e [include\customform.inc @ 183]00000000`094e9fe0 00000001`0000e09b : 00000000`094efeb0 00000000`094eac00 00000000`094ea080 00007fff`0e3c07b0 : CodaMinaTelnet!DESTROY+0x2a [include\customform.inc @ 198]00000000`094ea030 00000001`0002a551 : 00000000`00000000 00000000`064401e0 00000000`01645200 00000000`00000000 : CodaMinaTelnet!main+0xb37b00000000`094ea060 00000001`0001af95 : 00000000`00000000 00000000`00000000 00000000`00000062 00000000`094ebb30 : CodaMinaTelnet!DOBEFOREFINALIZATION+0x6100000000`094ea0b0 00000001`000109e9 : 00000000`00000020 00000000`094ebb30 00000000`0646af10 00000000`00000062 : CodaMinaTelnet!BEFOREFINALIZATION+0x1500000000`094ea0e0 00000001`00010bba : 00000000`06462c40 00000001`00360b40 00000000`094ea270 00000001`00088cd9 : CodaMinaTelnet!main+0xdcc900000000`094ea220 00000001`00010be0 : 00000000`00000000 00000000`00000000 00000000`06462c40 00000001`00360b40 : CodaMinaTelnet!main+0xde9a00000000`094ea250 00000001`0001ad4c : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : CodaMinaTelnet!main+0xdec000000000`094ea280 00000001`000178bd : 00000000`00000000 00000000`00000000 00000000`06439318 00000000`07f5a636 : CodaMinaTelnet!EXCEPTIONOCCURRED+0x5c [forms.pp @ 1915]00000000`094ea470 00007fff`0e4121ff : 00000001`00017610 00000000`00000000 00000000`00000000 00000000`00000000 : CodaMinaTelnet!main+0x14b9d00000000`094ea610 00007fff`0e3a0939 : 00000001`00002db6 00000000`094eab90 00000000`00000002 00000000`094eaf70 : ntdll!RtlpExecuteHandlerForUnwind+0xf00000000`094ea640 00000001`00017692 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!RtlUnwindEx+0x33900000000`094ead60 00007fff`0e41217f : 00000001`00017610 00000000`00000000 00000000`00000000 00000000`00000000 : CodaMinaTelnet!main+0x1497200000000`094eaf00 00007fff`0e3c1454 : 00000000`00000000 00000000`094eb470 00000000`094ebb30 00000000`00000000 : ntdll!RtlpExecuteHandlerForException+0xf00000000`094eaf30 00007fff`0e410cae : 00000000`00000000 00000000`00000000 00000000`00000300 00000000`00000000 : ntdll!RtlDispatchException+0x24400000000`094eb640 00000001`00011de0 : 00000000`00000000 00000001`00012eef 00000000`00000160 00000000`00150cc0 : ntdll!KiUserExceptionDispatcher+0x2e (TrapFrame @ 00000000`094eba68)00000000`094ebdf0 00000001`00011f10 : 00000000`094ebee0 00000000`094efde9 00000000`00000002 00000000`094e0000 : CodaMinaTelnet!main+0xf0c000000000`094ebe40 00000001`0001253d : 00000000`00000040 00000000`00000013 00000000`094ebf30 00000001`00011ef2 : CodaMinaTelnet!main+0xf1f000000000`094ebe80 00000001`0001124b : 00000000`04957e10 00000000`094ec008 00000000`094ebf30 00000001`00011192 : CodaMinaTelnet!main+0xf81d00000000`094ebec0 00000001`00009f2b : 00000000`07f664d0 00000000`ffffffff 00000000`00000013 00000001`000111cb : CodaMinaTelnet!main+0xe52b00000000`094ebef0 00000001`00009734 : 00000000`00000000 00000000`094efde9 00000000`06440138 00000000`06452d78 : CodaMinaTelnet!main+0x720b00000000`094ebf40 00000001`0002eae9 : 00000000`00000000 00007fff`0dfd19b1 00000000`00004638 00000000`094ec110 : CodaMinaTelnet!main+0x6a1400000000`094ebfe0 00000001`0002eb2d : 00000000`094ec1c0 00000001`000c8703 00000000`094ec1f0 00000001`00061599 : CodaMinaTelnet!DUMPEXCEPTIONCALLSTACK+0x19900000000`094ec180 00000001`0002ab9c : 0000000f`00000000 00000000`06452cc0 00000010`06462c40 00000000`06462c40 : CodaMinaTelnet!CUSTOMEXCEPTIONHANDLER+0x1d [mainform.pas @ 172]00000000`094ec1d0 00000001`0001af52 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : CodaMinaTelnet!HANDLEEXCEPTION+0x1ac [include\application.inc @ 1257]00000000`094ec240 00000001`000178bd : 00000000`00000000 00000000`00000000 00000000`0643b518 00000000`07f5a636 : CodaMinaTelnet!EXCEPTIONOCCURRED+0x262 [forms.pp @ 1927]00000000`094ec430 00007fff`0e4121ff : 00000001`00017610 00000000`00000000 00000000`00000000 00000000`00000000 : CodaMinaTelnet!main+0x14b9d00000000`094ec5d0 00007fff`0e3a0939 : 00000001`00002db6 00000000`094ecb50 00000000`00000002 00000000`094ecf30 : ntdll!RtlpExecuteHandlerForUnwind+0xf00000000`094ec600 00000001`00017692 : 00000000`00000000 00000000`00000000 00000000`00000000 00007fff`0e3fed41 : ntdll!RtlUnwindEx+0x33900000000`094ecd20 00007fff`0e41217f : 00000001`00017610 00000000`00000000 00000000`00000000 00000000`00000000 : CodaMinaTelnet!main+0x1497200000000`094ecec0 00007fff`0e3c1454 : 00000000`00000000 00000000`094ed430 00000000`094edaf0 00000000`00000000 : ntdll!RtlpExecuteHandlerForException+0xf00000000`094ecef0 00007fff`0e410cae : 00000000`094ed6a0 00007fff`0afd83f0 00000000`00000680 00007fff`0afd83d0 : ntdll!RtlDispatchException+0x24400000000`094ed600 00000000`00000000 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!KiUserExceptionDispatcher+0x2e ---------------------------------------------------------------------- 440bx · 2021-09-18 01:16 Quote from: powerpcer on September 18, 2021, 02:27:18 amfrom my point is that "CodaMinaTelnet!EXCEPTIONOCCURRED+0x262 [forms.pp @ 1927] CodaMinaTelnet!main+0x14b9d " what cause this exception? any tools can help? Without seeing the code, nothing else comes to mind. ---------------------------------------------------------------------- engkin · 2021-09-18 05:49 Just curious: What do you have around mainform.pas line 172? In your second post, can you tell us more about l, t, and r? Do you have an event assigned to the OnTerminate of the thread? ---------------------------------------------------------------------- powerpcer · 2021-09-19 05:13 my recent 2 exception that catch from dump, my thread at last will free event object. ..\..\Crypto\HlpTiger2.pas @ 1005 the line 1005 is the "end" of function this one doesnt raise Application exception Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ntdll!ZwWai tForAlertByThreadId+0x14ntdll!RtlpWaitOnAddressWithTimeout+0x81ntdll!R tlpWaitOnAddress+0xaentdll!RtlpWaitOnCriticalSection+0xfdntdll!RtlpEnt erCriticalSectionContended+0x1c4ntdll!RtlEnterCriticalSection+0x42Coda MinaTelnet!main+0x106fa [..\..\Crypto\HlpTiger2.pas @ 1005]CodaMinaTelnet!main+0xfd4b [..\..\Crypto\HlpTiger2.pas @ 1005]CodaMinaTelnet!main+0xf219 [..\..\Crypto\HlpTiger2.pas @ 1005]CodaMinaTelnet!main+0xf329 [..\..\Crypto\HlpTiger2.pas @ 1005]CodaMinaTelnet!main+0xf453 [..\..\Crypto\HlpTiger2.pas @ 1005]CodaMinaTelnet!main+0xe4cb [..\..\Crypto\HlpTiger2.pas @ 1005]CodaMinaTelnet!main+0x62b9 [..\..\Crypto\HlpTiger2.pas @ 1005]CodaMinaTelnet!main+0xcfc8 [..\..\Crypto\HlpTiger2.pas @ 1005]CodaMinaTelnet!main+0xcde7 [..\..\Crypto\HlpTiger2.pas @ 1005]CodaMinaTelnet!main+0xd06c [..\..\Crypto\HlpTiger2.pas @ 1005]CodaMinaTelnet!MAINTHREADWRITE+0xa1 [..\..\Crypto\HlpTiger2.pas @ 1005]CodaMinaTelnet!FPCADDS_$$_init$+0x8ef4 [..\..\Crypto\HlpTiger2.pas @ 1005]CodaMinaTelnet!FPCADDS_$$_init$+0x943a [..\..\Crypto\HlpTiger2.pas @ 1005]CodaMinaTelnet!DOWINDOWPROC+0x6c0 [..\..\Crypto\HlpTiger2.pas @ 1005]CodaMinaTelnet!WINDOWPROC+0x77 [..\..\Crypto\HlpTiger2.pas @ 1005]user32!UserCallWinProcCheckWow+0x2f 8user32!DispatchMessageWorker+0x249CodaMinaTelnet!APPPROCESSMESSAGES+0 xfe [..\..\Crypto\HlpTiger2.pas @ 1005]CodaMinaTelnet!HANDLEMESSAGE+0x27 [..\..\Crypto\HlpTiger2.pas @ 1005]CodaMinaTelnet!RUNLOOP+0x27 [..\..\Crypto\HlpTiger2.pas @ 1005]CodaMinaTelnet!APPRUN+0x28 [..\..\Crypto\HlpTiger2.pas @ 1005]CodaMinaTelnet!RUN+0x66 [..\..\Crypto\HlpTiger2.pas @ 1005]CodaMinaTelnet!main+0x7a [..\..\Crypto\HlpTiger2.pas @ 1005]CodaMinaTelnet!main+0x96 [..\..\Crypto\HlpTiger2.pas @ 1005]CodaMinaTelnet!main+0x143b0 [..\..\Crypto\HlpTiger2.pas @ 1005]CodaMinaTelnet!public_all+0x1d17 [..\..\Crypto\HlpTiger2.pas @ 10 05]kernel32!BaseThreadInitThunk+0x14ntdll!RtlUserThreadStart+0x21 this one raise application exception. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ntdll!ZwWai tForAlertByThreadId+0x14ntdll!RtlpWaitOnAddressWithTimeout+0x81ntdll!R tlpWaitOnAddress+0xaentdll!RtlpWaitOnCriticalSection+0xfdntdll!RtlpEnt erCriticalSectionContended+0x1c4ntdll!RtlEnterCriticalSection+0x42Coda MinaTelnet!main+0x106fa [..\..\Crypto\HlpTiger2.pas @ 1005]CodaMinaTelnet!main+0xfd4b [..\..\Crypto\HlpTiger2.pas @ 1005]CodaMinaTelnet!main+0xf219 [..\..\Crypto\HlpTiger2.pas @ 1005]CodaMinaTelnet!main+0xf329 [..\..\Crypto\HlpTiger2.pas @ 1005]CodaMinaTelnet!main+0xf453 [..\..\Crypto\HlpTiger2.pas @ 1005]CodaMinaTelnet!main+0xe4cb [..\..\Crypto\HlpTiger2.pas @ 1005]CodaMinaTelnet!main+0xa960 [..\..\Crypto\HlpTiger2.pas @ 1005]CodaMinaTelnet!main+0xd089 [..\..\Crypto\HlpTiger2.pas @ 1005]CodaMinaTelnet!main+0xcde7 [..\..\Crypto\HlpTiger2.pas @ 1005]CodaMinaTelnet!main+0xd06c [..\..\Crypto\HlpTiger2.pas @ 1005]CodaMinaTelnet!main+0xd59f [..\..\Crypto\HlpTiger2.pas @ 1005]CodaMinaTelnet!main+0xa958 [..\..\Crypto\HlpTiger2.pas @ 1005]CodaMinaTelnet!main+0xd089 [..\..\Crypto\HlpTiger2.pas @ 1005]CodaMinaTelnet!CLPED25519_$$_finalize_implicit$+0xb9 [..\..\Crypto\HlpTiger2.pas @ 1005]CodaMinaTelnet!main+0xdb27 [..\..\Crypto\HlpTiger2.pas @ 1005]CodaMinaTelnet!main+0xddf2 [..\..\Crypto\HlpTiger2.pas @ 1005]CodaMinaTelnet!main+0xde9a [..\..\Crypto\HlpTiger2.pas @ 1005]CodaMinaTelnet!main+0x7f [..\..\Crypto\HlpTiger2.pas @ 1005]CodaMinaTelnet!main+0x96 [..\..\Crypto\HlpTiger2.pas @ 1005]CodaMinaTelnet!main+0x143b0 [..\..\Crypto\HlpTiger2.pas @ 1005]CodaMinaTelnet!public_all+0x1d17 [..\..\Crypto\HlpTiger2.pas @ 1005]kernel32!BaseThreadInitThunk+0x14ntdll!RtlUserThreadStart+0x21 ---------------------------------------------------------------------- powerpcer · 2021-09-19 05:19 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit ClientThread;interfaceuses  Types,  {$ifdef unix}cthreads, {$endif}{$IFDEF WINDOWS}  winsock2,windows,{$ENDIF}  SysUtils,Classes,dateutils,syncobjs;const  BUFSIZE=4096;  {$IFDEF unix}    {$DEFINE TSOCKET := Integer}        {$DEFINE closesocket:=close}        INVALID_SOCKET = -1;        SOCKET_ERROR = -1;  {$ENDIF}type TCPClientThread = class(TThread)        public               mEvent:TEventObject;                isWaiting:boolean;    perhapsbeclosed:boolean;                serverhost:string;              serverport:integer;                isclosed:boolean;              procedure ThreadConnectTo(servIP:string;PORT,itimeout:integer);        function ConnectTo(servIP:string;PORT,itimeout:integer):integer;    procedure sendOut(data:pbyte;size:integer);    procedure close();              procedure Event(SocketEvent : Integer; iRead:Integer;rcvbuf: pbyte );virtual;abstract;                procedure disconnect();virtual;abstract;                constructor Create(b:boolean);                procedure dodestroy();virtual;abstract;    procedure doWork();    procedure doTerminate;override;                procedure Logtofile(sfilename:string);                procedure hexdump(pin:pbyte;isize:integer);  private    timeouts:integer;  protected    skt:Integer;                doLogs:boolean;              logfile:TextFile;                locker:TCriticalSection;              logfilename:string;    procedure Execute; override;                procedure LogMsg(s:String;const p:pbyte=nil;const psize:integer=0);end; implementationfunction GetIPByName(const Name:String):String;var  r:PHostEnt;  a:TInAddr;begin  Result:='';  r:= gethostbyname(PChar(Name));  if Assigned(r) then    begin      a:=PInAddr(r^.h_Addr_List^)^;      Result:=inet_ntoa(a);    end;end;procedure TCPClientThread.logMsg(s:String;const p:pbyte=nil;const psize:integer=0);begin        if doLogs then        begin          locker.Acquire;    writeln(logfile,s);                if p<>nil then                begin      hexdump(@p[0],psize);              end;    flush(logfile);                locker.Release;        end;end;procedure TCPClientThread.hexdump(pin:pbyte;isize:integer);var        Buff: array [0..16] of byte;        CountRead,i,j: Integer;        HexText: array [0..32] of byte;        HexText2: array [0..16] of byte;begin      i:=0;        while i < isize do        begin                CountRead := 0;                HexText[32]:=0;                Buff[16]:=0;                fillbyte(HexText[0],32,32);              fillbyte(Buff[0],16,32);                while ((CountRead+i)126) or (Buff[j]<32) then      begin        Buff[j]:=Byte('.');      end;      HexText2[j+1]:=Buff[j];    end;    logmsg(strpas(@HexText2));        end;end;procedure TCPClientThread.Logtofile(sfilename:string);begin  logfilename:=sfilename;        if not doLogs then        begin        {$I+}        AssignFile(logFile, logfilename);        //FileMode := fmOpenWrite;        Rewrite(logFile);        logmsg('log start...');      end;  doLogs:=true;end; constructor TCPClientThread.Create(b:boolean); begin  inherited Create(b);  Freeonterminate:=false;        mEvent := TEventObject.Create(nil,true,false,'');        isWaiting:=false;      perhapsbeclosed:=true;        skt:=-1;  locker:=TCriticalSection.Create;end; procedure TCPClientThread.ThreadC onnectTo(servIP:string;PORT,itimeout:integer);begin        serverhost:=servIP;        serverport:=port;        mEvent.SetEvent;end;function TCPClientThread.ConnectTo(servIP:string;P ORT,itimeout:integer):integer;var  wsd:WSADATA;  ret:integer;  server:sockaddr_in;  cTimeOut:integer;  ul,ul1:uint32;  timeout:Ttimeval;  r:Tfdset;begin  if (WSAStartup(MAKEWORD(2,0),wsd)<0) then          exit(-11);  skt:=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);    ul := 1;  ret := ioctlsocket(skt, long(FIONBIO), @ul);  if(ret<>NO_ERROR) then          exit(-3);     server.sin_family := AF_INET;  server.sin_port := htons(port);  server.sin_addr .s_addr := inet_addr(PAnsiChar(GetIPByName(servIP)));  if (server.sin_addr.s_addr = INADDR_NONE) then          exit(-1);   ret:=connect(skt,@server,sizeof(sockaddr_in));     FD_ZERO(r);  FD_SET(skt, r);  timeout.tv_sec := itimeout;   timeout.tv_usec :=0;  ret := select(0, nil, @r, nil, @timeout);  if ( ret <= 0 ) then  begin    closesocket(skt);                skt:=-1;    exit(-4);  end;   ul1 := 0 ;  ret := ioctlsocket(skt, long(FIONBIO), @ul1);  if (ret<>NO_ERROR) then  begin    closesocket(skt);                skt:=-1;    exit(-5);  end;  //writeln(stdout,'connect done skt=',skt);  perhapsbeclosed:=false;  result:=0;        serverhost:=servIP;        serverport:=port;end;procedure TCPClientThread.sendOut(data:pbyte;size:integer);begin  send(skt,data,size,0);end;procedure TCPClientThread.close();begin  if skt>0 then    closesocket(skt);        skt:=-1;        perhapsbeclosed:=true;          //if doLogs then        //begin  //  if isclosed=false then  //    closefile(logFile);  //end;        isclosed:=true;end;procedure TCPClientThread.Execute;var  ustart,uend:Uint32;  res:integer;        timeval:TTimeVal;        BufRev:pbyte;//bufferbegin  //ustart:=MilliSecondOfTheday(now);  BufRev:=allocmem(BUFSIZE);  timeval.tv_sec:=timeouts*1000;  timeval.tv_usec:=50;  //res:=setsockopt(skt,SOL_SOCKET,SO_RCVTIMEO,@ti meval,sizeof(timeval));  while Terminated=false do        begin        if skt=-1 then                begin                isWaiting:=true;                        if Terminated then                          continue;                        logmsg('start Waiting..');      mEvent.WaitFor(INFINITE);      mEvent.ResetEvent;                      logmsg('start check Terminated..');                        if Terminated then                          continue;      logmsg('start working..');                        if skt=-1 then                      begin        res:=ConnectTo(serverhost,serverport,5);                      if res<0 then                        begin          logmsg('connect fail..');                          Event(4,0,nil);                        continue;                        end;                      end;                        logmsg('connect fail to live..');                        isWaiting:=false;                      Event(1,0,nil);                end;          while  (skt>0)   do  begin                res:=recv(skt,BufRev[0],BUFSIZE,0);              if (res>0) then                begin                        Event(3,res,@BufRev[0]);                end                else                      if (res<=0) then                begin                              Event(2,res,@BufRev[0]);                                disconnect();                        break;                end;              end;  end;//end while true  logmsg('Terminated..');  FreeMem(BufRev);        mEvent.free;        locker.free;        dodestroy(); end; procedure TCPClientThread.doWork();begin  mEvent.SetEvent;  logmsg('lets working..');  isWaiting:=false;end;procedure TCPClientThread.doTerminate;begin  // Signal event to wake up the thread  CLOSE();  freeOnTerminate:=true;  // Base Terminate method (to set Terminated=true)  Terminate;        logmsg('lets terminate..');        mEvent.SetEvent;end;end.   Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  ptermrec=^TTermRec;  TTermRec=record    r:Prect;    zorder:integer;  t:TCodaMinaTerminal;    mmi:TMenuItem;  end; procedure Tmainfrm.FormClose(Sender: TObject; var CloseAction: TCloseAction);var  l:PTermRec; begin  l:=telnet.loopforward();  i:=telnet.getCount();  while l<>nil do  begin       l^.t.doTerminate();       //sleep(50);        Dispose(l^.r);       Dispose(l);       l:=telnet.loopforward();  end;  telnet.Free;end;