zmwatch.pl does not free file handles.

Forum for questions and support relating to the 1.24.x releases only.
Post Reply
mastertheknife
Posts: 679
Joined: Wed Dec 16, 2009 4:32 pm
Location: Israel

zmwatch.pl does not free file handles.

Post by mastertheknife » Thu Feb 24, 2011 7:25 pm

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.

mastertheknife
Posts: 679
Joined: Wed Dec 16, 2009 4:32 pm
Location: Israel

Re: zmwatch.pl does not free file handles.

Post by mastertheknife » Sat May 07, 2011 8:27 am

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.
Last edited by mastertheknife on Fri May 20, 2011 11:14 am, edited 1 time in total.
Kfir Itzhak.

User avatar
Normando
Posts: 219
Joined: Sun Aug 17, 2008 5:34 am
Location: Rosario - Argentina

Re: zmwatch.pl does not free file handles.

Post by Normando » Tue May 10, 2011 2:50 pm

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.

mastertheknife
Posts: 679
Joined: Wed Dec 16, 2009 4:32 pm
Location: Israel

Re: zmwatch.pl does not free file handles.

Post by mastertheknife » Tue May 10, 2011 3:13 pm

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?
Kfir Itzhak.

mastertheknife
Posts: 679
Joined: Wed Dec 16, 2009 4:32 pm
Location: Israel

Re: zmwatch.pl does not free file handles.

Post by mastertheknife » Tue May 10, 2011 3:15 pm

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.
Kfir Itzhak.

User avatar
Normando
Posts: 219
Joined: Sun Aug 17, 2008 5:34 am
Location: Rosario - Argentina

Re: zmwatch.pl does not free file handles.

Post by Normando » Tue May 10, 2011 3:56 pm

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".

mastertheknife
Posts: 679
Joined: Wed Dec 16, 2009 4:32 pm
Location: Israel

Re: zmwatch.pl does not free file handles.

Post by mastertheknife » Tue May 10, 2011 4:13 pm

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
Kfir Itzhak.

User avatar
Normando
Posts: 219
Joined: Sun Aug 17, 2008 5:34 am
Location: Rosario - Argentina

Re: zmwatch.pl does not free file handles.

Post by Normando » Tue May 10, 2011 4:28 pm

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?

mastertheknife
Posts: 679
Joined: Wed Dec 16, 2009 4:32 pm
Location: Israel

Re: zmwatch.pl does not free file handles.

Post by mastertheknife » Tue May 10, 2011 4:56 pm

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.
Kfir Itzhak.

User avatar
Normando
Posts: 219
Joined: Sun Aug 17, 2008 5:34 am
Location: Rosario - Argentina

Re: zmwatch.pl does not free file handles.

Post by Normando » Tue May 10, 2011 5:44 pm

Thanks. I will test it.

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests