Recent

Author Topic: Daemon app crashes on Windows after some time regarding ntdll.dll  (Read 3687 times)

antispam88

  • Jr. Member
  • **
  • Posts: 60
Hi,
we have two different services for windows 10/2019 x64. They are build with the lazdaemon package.
It is working as expected for few hours up to several days. Then the service crashes with following event view entry:
Code: Pascal  [Select][+][-]
  1. Faulting application name: aservice.exe, version: 4.4.0.7, time stamp: 0x00000000
  2. Faulting module name: ntdll.dll, version: 10.0.14393.3986, time stamp: 0x5f77fd0d
  3. Exception code: 0xc0000374
  4. Fault offset: 0x00000000000f6fb3
  5. Faulting process id: 0x10a4
  6. Faulting application start time: 0x01d6d7a4fd4d31ea
  7. Faulting application path: C:\aservice\bin\aservice.exe
  8. Faulting module path: C:\Windows\SYSTEM32\ntdll.dll
  9. Report Id: a5684795-7a9d-4cc4-b4ac-39136047d481
  10. Faulting package full name:
  11. Faulting package-relative application ID:  

We have created our service like the cleandirs example.
Code: Pascal  [Select][+][-]
  1.   TAService = class(TDaemon)
  2.     procedure DataModuleCreate(Sender: TObject);
  3.     procedure DataModuleDestroy(Sender: TObject);
  4.     procedure DataModuleShutDown(Sender: TCustomDaemon);
  5.     procedure DataModuleStart(Sender: TCustomDaemon; var OK: boolean);
  6.     procedure DataModuleStop(Sender: TCustomDaemon; var OK: boolean);
  7.   private
  8.     _working_thread: TWorkingThead;
  9.   end;

We tried to cover every line of code for exception handling. And we also using the Application.OnException event to log the error without success.
Has anyone made some experience with uncaught expections in services? We have already tried to change the release settings to debug without a result.

Best regards,
antispam88

Lazarus: 3.0.8
FPC: 3.0.4
X86x_64-wind64-win32/win64
Windows 10 prof. 64x

ASBzone

  • Hero Member
  • *****
  • Posts: 678
  • Automation leads to relaxation...
    • Free Console Utilities for Windows (and a few for Linux) from BrainWaveCC
Re: Daemon app crashes on Windows after some time regarding ntdll.dll
« Reply #1 on: February 25, 2021, 09:19:23 pm »
According to the following URL, the error message you are receiving is indicative of a heap corruption issue:

https://social.technet.microsoft.com/Forums/windows/en-US/578396fd-29c0-4dd3-b002-5e2e8df1b398/exception-code-0xc0000374?forum=w7itprogeneral

You might want to run with heaptrc and see about tracking this issue down that way.

https://www.freepascal.org/docs-html/rtl/heaptrc/usage.html
-ASB: https://www.BrainWaveCC.com/

Lazarus v2.2.7-ada7a90186 / FPC v3.2.3-706-gaadb53e72c
(Windows 64-bit install w/Win32 and Linux/Arm cross-compiles via FpcUpDeluxe on both instances)

My Systems: Windows 10/11 Pro x64 (Current)

440bx

  • Hero Member
  • *****
  • Posts: 3944
Re: Daemon app crashes on Windows after some time regarding ntdll.dll
« Reply #2 on: February 25, 2021, 10:45:52 pm »
Exception code: 0xc0000374
As ASBzone pointed out, that is the NTSTATUS indicating that a heap has been corrupted.  If interested, that status and many others are documented in https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/596a1078-e883-4972-9bbc-49e60bebca55

Errors of that nature are commonly caused by a buffer overrun.  What makes them difficult to find is that it is common for the overrun to end up causing problems much after it has occurred.  Another common source of problems is allocating a buffer and not initializing it, potentially resulting in using random data later as a value that can lead to the corruption of a different memory block (e.g, data used as an offset into other data.)

That's the first "profilactic" step, ensure all allocated memory blocks are properly initialized before being used (usually to binary zeroes), that can be helpful in figuring out where the problem takes place.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

 

TinyPortal © 2005-2018