Static conf/html keeps files open

Hi all,

I’ve a python script that is triggered every minutes and it generates a few graphs from grafana in PNG format.
These graphs are placed in the conf/html folder and are displayed in the basic ui.
The script first generates the graphs with temporary names and after rendering all graphs it replaces the old ones by removing them and renaming the new ones.

The problem is that it looks like openhab is keeping these image files open for several minutes. In this case the replacing of the new graphs fails since the python script can’t remove the old one since it is still in use by openhab.
This problem does not happen all the time. It looks like the files are released after a few minutes.
I’m using openhab on a windows system and I’m using build 1070.

See a screenshot of the handles in ProcessExplorer (open for multiple minutes):
image

An example of the definitions in my sitemap for the images:

Frame label="Vloerverwarming (Circuit 2)" {
	Image url="http://localhost:8080/static/Graphs/HeatingFloorHeating.png" refresh=150000
}

Error in openhab logs:

2017-11-03 09:00:46.469 [INFO ] [marthome.model.script.GenerateGraphs] - Generated graphs.
2017-11-03 09:05:43.909 [INFO ] [marthome.model.script.GenerateGraphs] - Generated graphs.
2017-11-03 09:10:43.532 [INFO ] [marthome.model.script.GenerateGraphs] - Generated graphs.
2017-11-03 09:15:44.374 [INFO ] [marthome.model.script.GenerateGraphs] - Generated graphs.
2017-11-03 09:15:44.374 [INFO ] [rthome.model.script.GenerateGraphs] - Traceback (most recent call last):
  File "C:\OpenHAB\conf\html\Graphs\GenerateGraphs.py", line 35, in <module>
    os.remove(existing)
WindowsError: [Error 5] Access is denied: 'C:\\OpenHAB\\conf\\html\\Graphs\\HeatingFloorHeating.png'
2017-11-03 09:20:44.385 [INFO ] [marthome.model.script.GenerateGraphs] - Generated graphs.
2017-11-03 09:20:44.386 [INFO ] [rthome.model.script.GenerateGraphs] - Traceback (most recent call last):
  File "C:\OpenHAB\conf\html\Graphs\GenerateGraphs.py", line 35, in <module>
    os.remove(existing)
WindowsError: [Error 5] Access is denied: 'C:\\OpenHAB\\conf\\html\\Graphs\\HeatingFloorHeating.png'
2017-11-03 09:25:43.875 [INFO ] [marthome.model.script.GenerateGraphs] - Generated graphs.
2017-11-03 09:25:43.875 [INFO ] [rthome.model.script.GenerateGraphs] - Traceback (most recent call last):
  File "C:\OpenHAB\conf\html\Graphs\GenerateGraphs.py", line 35, in <module>
    os.remove(existing)
WindowsError: [Error 5] Access is denied: 'C:\\OpenHAB\\conf\\html\\Graphs\\HeatingFloorHeating.png'
2017-11-03 09:30:45.085 [INFO ] [marthome.model.script.GenerateGraphs] - Generated graphs.
2017-11-03 09:35:52.874 [INFO ] [marthome.model.script.GenerateGraphs] - Generated graphs.
2017-11-03 09:35:52.874 [INFO ] [rthome.model.script.GenerateGraphs] - Traceback (most recent call last):
  File "C:\OpenHAB\conf\html\Graphs\GenerateGraphs.py", line 35, in <module>
    os.remove(existing)
WindowsError: [Error 5] Access is denied: 'C:\\OpenHAB\\conf\\html\\Graphs\\HeatingFloorHeating.png'

You can see that it goes fine in the beginning and then fails, also before the last fail it succeeds once.

Is this a bug or am I abusing the purpose of the conf/html folder?

Thanks!

Greetings,
Frederic

EDIT: it only happens, but not always, when the page where the graphs are displayed is open in basicui. If I’m on another page without the graphs, it never happens.

I suspect that it is caused by the refresh rate used on the sitemap for that Image.

Is there a reason you are not just using the static URL straight from Grafana and bypass this relatively complicated approach? That is what I use and it works on my local LAN, remotely, through myopenhab.org and in the phone apps. And all you need to do is use the pre-rendered image URL for the chart in Grafana.

Hi,

I was also thinking that the refresh rate was causing this issue but then I would expect that the file stays open for a mather of milliseconds and not minutes.
I’m not using the static URL since it takes way to long to generate the graphs. I have 5 graphs in that part of the sitemap and it takes almost 30 seconds to display all graphs. That’s why I use this approach.

Greetings,
Frederic

Anybody else any idea on this?

Greetings,
Frederic

What version of OH are you running?

I seem recall seeing an issue about image files not being closed, but I can’t seem to find it now. I’ll keep looking.

This is the one I was thinking of. Not sure if it is applicable to what you’re seeing.

It is most likely related to this one java.io.IOException: Too many open files

Hi,

Thanks for your reply and help.
I’m using version 1070 right now which is from Oct 25.
This PR you are referring to has been merged on Oct 5 so this should already be included in version 1070, right?

Greetings,
Frederic

Hi,

Thanks for your reply.
Shouldn’t this already be included in build 1070 since this one has been build on Oct 25 and the PR has been merged on Oct 5?

Greetings,
Frederic

Yes it should that is why I referred to the other topic as well because it is (also) the browser keeping connections open and causing the problem.

Yes, the fix for the issue I referenced was included in the 10/10 ESH stable release. So, if you’re on 1070, then the issue @martinvw referenced probably is the culprit.

Oh ok, I was confused, I didn’t realize you were referring another issue.
So is there anything I can do to solve this or is there anything else I can provide you to further investigate this issue?