1

I have a SCADA system (Siemens WinCC Classic 7.5) where there is data exchange between a storage facility and my system, based on text files.

Sometimes (very rarely, maybe 1 in 2000) it crashes the connection to the network drives where the files are exchanged. The only way to fully recover is to restart the server (Windows 2019).

I suspect that what happens is, that one file is reopened by the SCADA program, before it is actually closed again, because the file is processed cyclically every 1 seconds.

Closing of the file is implemented (with error handling as well) and works during normal operation. However, if the file is opened and not closed by the same function, I lack a way to "forcefully" close it.

Does anyone know of the golden solution to finding and closing/terminating open files without restarting the entire server?

I use fopen() to open the file, and it's normally closed with fclose(). This works fine normally. But if the file is opened with fopen() and not closed in the same function, the file remains open and cannot be renamed/deleted without restarting.

I hope the above makes sense, because it's a pretty complex system so it's difficult to summarize in such short terms. I've searched far and wide and not been able to find a suitable solution. This is made even more difficult by being locked by only having the Siemens-enabled C-functions.

mbk
  • 23
  • 3
  • 1
    In what situation does the function leave the file open? Perhaps it's becoming clearer if you share the actual code. – Ted Lyngmo Nov 14 '22 at 12:09
  • 1
    Re “I use `fopen()` to open the file”: So this is a bug in your code? You use `fopen` to open the file, and you sometimes fail to close it? Do you want help finding the bug or help making a workaround for your bug? Either way, change calls to `fopen` and `fclose` to call a different routine, like `fopenTraced` and `fcloseTraced`. In `fopenTraced`, record all open files in your own data structure, and call `fopen` to open the file. In `fcloseTraced`, remove the open file from the data structure… – Eric Postpischil Nov 14 '22 at 12:20
  • … Then, at any time you choose, you can call some other routine `fcheckTraced` that will examine your data structure and either tell you about files that have been opened but not closed (for debugging) and/or will close them (for a workaround). You could add some code to ignore files that should remain open. – Eric Postpischil Nov 14 '22 at 12:21
  • How about actually checking if every fopen() call succeeded? And if not, handle errors gracefully from there. That ought to solve the problem, or...? Because you can't detect "if the file is opened and not closed by the same function" - if that's a bug, then the solution is to fix all such bugs. – Lundin Nov 14 '22 at 14:06
  • @EricPostpischil Thanks for the suggestion, I will try to implement something like this. As sort of a general response to you all, I could've been clearer in my original post. I already check if the `fopen()` was successful, and all scripts already have an fclose and ensures fclose is called. However, as I tried to say in my OP, I fear that maybe sometimes the SCADA program will call the same function again before it was actually done the first time, and hence open the file a second time (building up "opens", if that makes sense) – mbk Nov 15 '22 at 09:57
  • How about a test with only local files instead of using a network-share? I’m guessing that sometimes the network is not stable for this kind of fast “file-operations”. – Per Dahlqvist Nov 17 '22 at 09:08

0 Answers0