Page 1 of 1

zmwatch.pl does not free file handles.

Posted: Thu Feb 24, 2011 7:25 pm
by mastertheknife
Original problem is here: http://www.zoneminder.com/forums/viewto ... c&start=30

Few days after installing munin, i noticed the open file handles just keeps growing, almost up to the max and then starts over (zmwatch.pl crashes?).
Image

This is confirmed to be zmwatch.pl. After killing it, the number goes back to normal but after zmwatch.pl comes back alive, the number starts increasing at a rate of about 1 per 5-10 seconds.

Code: Select all

p1400 kfir # cat /proc/sys/fs/file-nr
1071    0       76956
p1400 kfir # cat /proc/sys/fs/file-nr
1072    0       76956
p1400 kfir # cat /proc/sys/fs/file-nr
1073    0       76956
p1400 kfir # cat /proc/sys/fs/file-nr
1090    0       76956
From another terminal:

Code: Select all

p1400 Memory # cat /proc/28753/maps | grep mmap | wc -l
10
p1400 Memory # cat /proc/28753/maps | grep mmap | wc -l
11
p1400 Memory # cat /proc/28753/maps | grep mmap | wc -l
12
p1400 Memory # cat /proc/28753/maps | grep mmap | wc -l
13
p1400 Memory # cat /proc/28753/maps | grep mmap | wc -l
30
It seems that in the while loop inside zmwatch.pl, it keeps re-opening the shared memory (i'm using memory mapped files, not shm stuff). Perhaps the zmMemVerify call, calling ZmMemAttach and for some reason causing it to open the memory mapped file again.

mastertheknife.

Re: zmwatch.pl does not free file handles.

Posted: Sat May 07, 2011 8:27 am
by mastertheknife
After some investigation with the perl debugger(ugh) i found the reason its happening.
$monitor is a new variable at every monitor iteration, which is why $monitor->{MMapAddr} is not being stored between loop iterations.

mastertheknife.

Re: zmwatch.pl does not free file handles.

Posted: Tue May 10, 2011 2:50 pm
by Normando
Master, thanks for you researching.

But I have a dude. If I change the monitor settings or remove or adding a new monitor, then zmwatch can't know if there is any new or removed monitor until I will restart ZoneMinder.

Re: zmwatch.pl does not free file handles.

Posted: Tue May 10, 2011 3:13 pm
by mastertheknife
Normando wrote:Master, thanks for you researching.

But I have a dude. If I change the monitor settings or remove or adding a new monitor, then zmwatch can't know if there is any new or removed monitor until I will restart ZoneMinder.
zmwatch.pl fetches the list of monitors from the database before every iteration so it does know about removed\new monitors. What ZM version are you using?

Re: zmwatch.pl does not free file handles.

Posted: Tue May 10, 2011 3:15 pm
by mastertheknife
Also, to fix the zmwatch.pl not freeing handles, edit scripts/zmwatch.pl.in (or /usr/bin/zmwatch.pl for an installed system) and do the following changes:

Find:

Code: Select all

my $image_time = zmGetLastWriteTime( $monitor );
Add this below it:

Code: Select all

zmMemInvalidate( $monitor );
Find:

Code: Select all

my $image_time = zmGetLastReadTime( $monitor );
Add this below it:

Code: Select all

zmMemInvalidate( $monitor );
Hopefully this will be integrated into the SVN.
mastertheknife.

Re: zmwatch.pl does not free file handles.

Posted: Tue May 10, 2011 3:56 pm
by Normando
mastertheknife wrote:zmwatch.pl fetches the list of monitors from the database before every iteration so it does know about removed\new monitors. What ZM version are you using?
Hi Master.

I am using the latest checked out code from SVN.

I don't know if I thinking correctly, but if you put the code that load monitors outside the "while" loop, then there is no way to get any monitor changes (added, removed, etc) until you restart zoneminder or zmwatch script.

Look into zmtrigger.pl script how load monitor after a predefined time. The subroutine is "loadMonitors".

Re: zmwatch.pl does not free file handles.

Posted: Tue May 10, 2011 4:13 pm
by mastertheknife
Normando wrote:
mastertheknife wrote:zmwatch.pl fetches the list of monitors from the database before every iteration so it does know about removed\new monitors. What ZM version are you using?
Hi Master.

I am using the latest checked out code from SVN.

I don't know if I thinking correctly, but if you put the code that load monitors outside the "while" loop, then there is no way to get any monitor changes (added, removed, etc) until you restart zoneminder or zmwatch script.
Thats correct. but i ended up going with a much simpler route because i don't really know perl so i simply added the missing call to free the shared memory handles after every access\iteration.

mastertheknife

Re: zmwatch.pl does not free file handles.

Posted: Tue May 10, 2011 4:28 pm
by Normando
mastertheknife wrote:Thats correct. but i ended up going with a much simpler route because i don't really know perl so i simply added the missing call to free the shared memory handles after every access\iteration.
mastertheknife
So you was fixed adding only "zmMemInvalidate( $monitor )" after each zmGetxxx sentences without define the monitor array outside the while loop?

Re: zmwatch.pl does not free file handles.

Posted: Tue May 10, 2011 4:56 pm
by mastertheknife
Normando wrote:
mastertheknife wrote:Thats correct. but i ended up going with a much simpler route because i don't really know perl so i simply added the missing call to free the shared memory handles after every access\iteration.
mastertheknife
So you was fixed adding only "zmMemInvalidate( $monitor )" after each zmGetxxx sentences without define the monitor array outside the while loop?
Yes. It works nicely on my machine.

Re: zmwatch.pl does not free file handles.

Posted: Tue May 10, 2011 5:44 pm
by Normando
Thanks. I will test it.