Recent

Author Topic: [Solved] My program freezes after running for several days  (Read 945 times)

krolikbest

  • Sr. Member
  • ****
  • Posts: 250
Re: My program freezes after running for several days
« Reply #15 on: October 28, 2024, 10:18:40 am »
Quote
While Not EOF(fLog) Do
      Begin
      //Parse file one line at a time 
      //do stuff with lines from file
     //And close files
  Close(fLog);
  Close(fDat);
  Close(fIn);
  Close(fSys);
  Close(fUn);
  DatFiles.Free;
where is the "end"? for this block of code? at the end of this block or somewhere there
Quote
//And close files

Such a loose guesses, could it be that you are trying to open a file when it is already opened (e.g. in last sequence was not closed because some other processes took time and in new sequence it is still open?

Thaddy

  • Hero Member
  • *****
  • Posts: 16138
  • Censorship about opinions does not belong here.
Re: My program freezes after running for several days
« Reply #16 on: October 28, 2024, 10:21:02 am »
Also note your sqlite db might keep handles open.
If I smell bad code it usually is bad code and that includes my own code.

Wilko500

  • Full Member
  • ***
  • Posts: 108
Re: My program freezes after running for several days
« Reply #17 on: November 02, 2024, 05:26:01 pm »
Update and probable cause identified

A power failure does not keep files open after a restart.
Yes, I agree but a power failure followed by restart does cause (sometimes) damage to the log file created by the inverter monitoring program (Aurora Communicator, provided by the inverter manufacturer) thus extra initialisation lines may appear in the log file in an unusual order. My code attempts to anticipate and handle this kind of event.

While reviewing my code and debug log file following another program freeze of the same kind I did find that in one of my procedures I had unintentionally omitted code in the Exception that would have logged an exception.

On both of the "freeze" I ah seen from the macOS Activity monitor that there was a single data file involved.  I have concluded that there was some issue with that file (and my code) that had caused an exception.  That exception had been caught by the Try - Except and the program execution continued WITHOUT any message being output and the file not being closed.  This had then repeated until open file limit exceeded and program freeze.

Thank you all for your observations, comments and suggestions. I will mark this thread as solved.




MacBook Pro mid 2015 with OS Monterey 12.7.6
FPC 3.3.1 Lazarus 3.99
FPC 3.2.2 Lazarus 3.4

 

TinyPortal © 2005-2018