Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(FreeBSD)(CLANG) Sendfile7 support is broken #3505

Closed
abishai opened this issue Jun 12, 2022 · 77 comments
Closed

(FreeBSD)(CLANG) Sendfile7 support is broken #3505

abishai opened this issue Jun 12, 2022 · 77 comments

Comments

@abishai
Copy link
Contributor

abishai commented Jun 12, 2022

I try to build ZM 1.36.19 and after recent changes in https://github.com/ZoneMinder/zoneminder/blob/1.36.19/src/zm_sendfile.h it doesn't compile

/usr/ports/multimedia/zoneminder/work/zoneminder-1.36.19/src/zm_sendfile.h:29:17: error: no matching function for call to 'sendfile'
  ssize_t err = sendfile(in_fd, out_fd, *offset, size, nullptr, &size, 0);
                ^~~~~~~~
/usr/include/sys/socket.h:705:5: note: candidate function not viable: no known conversion from 'size_t *' (aka 'unsigned long *') to 'off_t *' (aka 'long *') for 6th argument
int     sendfile(int, int, off_t, size_t, struct sf_hdtr *, off_t *, int);

I can revert the offending argument to off_t back, but is it a viable solution?

@connortechnology
Copy link
Member

Um.. so I think we can get away with just casting ... ssize_t and off_t are basically the same.

So how about this?

#elif HAVE_SENDFILE7_SUPPORT
  off_t sent;
  int err = sendfile(in_fd, out_fd, *offset, size, nullptr, &sent, 0);
  if (err && errno != EAGAIN)
    return -errno;
  return static_cast<ssize_t>(sent);
#else

@abishai
Copy link
Contributor Author

abishai commented Jun 17, 2022

--- src/zm_sendfile.h.orig	2022-06-12 09:18:29 UTC
+++ src/zm_sendfile.h
@@ -17,7 +17,7 @@ extern "C" {
 
 /* Function to send the contents of a file. Will use sendfile or fall back to reading/writing */
 
-ssize_t zm_sendfile(int out_fd, int in_fd, off_t *offset, size_t size) {
+ssize_t zm_sendfile(int out_fd, int in_fd, off_t *offset, off_t size) {
 #ifdef HAVE_SENDFILE4_SUPPORT
   ssize_t err = sendfile(out_fd, in_fd, offset, size);
   if (err < 0) {

^ My idea was to change argument, but if you want to keep it, casting works as well. I'll apply yours variant then. Thank you!

@connortechnology
Copy link
Member

The issue is that we were abusing the stack variable size. Which really.... we shouldn't do. So I think this looks better. Does it compile and work there? If so I'll merge it.

@abishai
Copy link
Contributor Author

abishai commented Jun 18, 2022

The code compiles, but something is broken in zms. Monitor live view is constantly refreshes.

The logs is filled with

2022-06-18 13:18:57 | web_php |   | 3124 | ERR | Unable to get semaphore. | includes/functions.php | 1907
-- | -- | -- | -- | -- | -- | -- | --
2022-06-18 13:18:57 | zms_m1 |   | 273810 | WAR | Unable to send stream frame: Broken pipe | zm_monitorstream.cpp | 412
2022-06-18 13:18:56 | web_php |   | 3124 | ERR | Unable to get semaphore. | includes/functions.php | 1907

I'm building with DHAVE_SENDFILE=0
Without it I'm receiving zmc crash by signal 11 on startup, but I set this knob before. I was unable to solve this issue since I ported 1.30 to FreeBSD. I remember ZM has a fallback if sendfile is not available. Maybe it's broken now? Or flickering is another regression? It looks like zms sends one frame and than reloads and start to send initial frame one more time and so on.

The last version that works is v1.36.12. Probably, I should try bisect or revert some obvious places to see if it helps.

@abishai
Copy link
Contributor Author

abishai commented Jun 18, 2022

Probably, it's not zms, but zmc.

Found locked packet when trying to free up video packets. This basically means that decoding is not keeping up.

It looks like zmc provides broken video to all subsystems.

  • add -
    OK, I investigated more and looks like zms and zmc are OK. Direct link to zms binary provides normak stream.

Now I have the following suspicious places:

  1. Semaphore error (looks like this is the source of the problem)
  2. Policy issue. Content Security Policy: The page’s settings observed the loading of a resource at eval (“script-src”). A CSP report is being sent.
  3. Incorrect link generation to zms while behind reverse proxy. http instead of https. I believe this one was solved a long time ago.

@abishai
Copy link
Contributor Author

abishai commented Jun 18, 2022

Semaphore issue was simple enough - for semaphore support I need php74-sysvsem PHP extension. Stream is working now.
On the other side, I see a lot of

"Found locked packet when trying to free up video packets. This basically means that decoding is not keeping up." warning messages.

and

Analysis daemon for 8 Monitor-8 needs restarting, time since last analysis 66 seconds (1655563844-1655563778)

for every monitor in Record state (with or without analysis enabled)

"Locked packets" are filling logs very fast. Monitors are ffmpeg 5MP with 6 FPS 6000 VBR in passthrough mode. I see, the severity of such messages was bumped recently from Debug to Warning. Who is not keeping up here?

Analysis issue is the most troublesome - it forces zmc to reload every minute. I think this is not FreeBSD specific problem.

Also, content policy should be relaxed to unblock eval() in js if it's used.

script-src 'unsafe-eval' 'self'

solves script error.

The problem with http:// link is tricky. I didn't find exact place.

I see the following in the logs:

Setting to streaming: [https://***](https://***)
Loading mixed (insecure) display content “http://***” on a secure page
Image stream has loaded! starting streamCmd for 563970

So, it detects correct URL with https:// but after that tried to use http://
Something very confusing.

@connortechnology
Copy link
Member

My experience with 5MP cams is that we cannot decode, and do motion detection on them fast enough.

Yes you do need semaphore support.

Can we please leave this discussion to the issue at hand? Being sendfile implementation. What is the status of that? Is it working with SENDFILE=1?

@abishai
Copy link
Contributor Author

abishai commented Jun 21, 2022

I agree, should I create separate issues for the problems discovered? Issues with record only monitors is rather serious.

As for sendfile implementation:

  1. With the patch, ZoneMinder compiles.
  2. Without SENDFILE=0 zmc crashes on strartup with signal 11. I think, we need stack trace, right?

@badrpc
Copy link
Contributor

badrpc commented Dec 2, 2022

I think sendfile on FreeBSD can only work with sockets. When I built it with sendfile support, I wasn't able to watch recorded events with the following error in logs:

zms_e95.log:12/01/22 22:11:12.762041 zms_e95[101577].WAR-zm_eventstream.cpp/1091 [Unable to send raw frame 1: Socket operation on non-socket 356482 remaining]
zms_e95.log:12/01/22 22:11:12.762191 zms_e95[101577].ERR-zm_eventstream.cpp/730 [Can't send /var/db/zoneminder/events/3/2022-11-29/95/00001-capture.jpg: Socket operation on non-socket]

ERRORS section of the manual lists

     [ENOTSOCK]		The s argument is not a	socket.

Here s is the second argument of sendfile.

@connortechnology
Copy link
Member

@abishai what is the state of this ? I there something I can merge to master?

@abishai
Copy link
Contributor Author

abishai commented Dec 6, 2022

@connortechnology With your patch, ZM compiles and works with SENDFILE=0. According @badrpc it looks like SENDFILE must be 0 on FreeBSD.

As for 'supplemental' issues mentioned in #3505 (comment) record one is too serious and blocks my migration from 1.36.12 But maybe it was fixed in latest versions of ZM.

Probably, I'm the only user of ZM on FreeBSD, at least nobody complains that we have outdated 1.36.12 in port tree.

I think, we can formally close this issue and hope that latest version of ZM operates better than 1.36.19.

@VVD
Copy link

VVD commented Jan 9, 2023

@abishai, I'm installed 1.36.12 today!
It have a lot of Deprecated warnings with php 8.1.
Begin to update port to 1.36.32, got same build error, create patch, want to create issue… and found this one. :-D

My patch is:

--- src/zm_sendfile.h.orig
+++ src/zm_sendfile.h
@@ -17,7 +17,7 @@ extern "C" {
 
 /* Function to send the contents of a file. Will use sendfile or fall back to reading/writing */
 
-ssize_t zm_sendfile(int out_fd, int in_fd, off_t *offset, size_t size) {
+ssize_t zm_sendfile(int out_fd, int in_fd, off_t *offset, ssize_t size) {
 #ifdef HAVE_SENDFILE4_SUPPORT
   ssize_t err = sendfile(out_fd, in_fd, offset, size);
   if (err < 0) {

Let's try together update port!

@abishai
Copy link
Contributor Author

abishai commented Jan 12, 2023

Is 1.36.32 has deprecated warnings fixed?

Can you check that Record mode works as well?
I've experienced watchdog issue for every monitor in Record mode in 1.36.19. But, as I doubt that this one FreeBSD specific, maybe it's fixed in 1.36.32

Analysis daemon for 8 Monitor-8 needs restarting, time since last analysis 66 seconds (1655563844-1655563778)

@connortechnology
Copy link
Member

I would expect those to either be fixed, or the issue is outside ZM.

php8.1 deprecation warnings are simply turned off in 1.36.32.

@connortechnology
Copy link
Member

So this patch compiles fine here.... I'd be happy to merge it...

@hjf
Copy link

hjf commented Jan 12, 2023

I compiled 1.36.32 with this patch and I don't see any issues so far, save for icons not visible in Web UI. Recordings and montage work fine, and no errors in the log. I sent an email to @abishai with the ports tree patch

@badrpc
Copy link
Contributor

badrpc commented Jan 12, 2023

@hjf can you watch recorded events?

@hjf
Copy link

hjf commented Jan 12, 2023

@hjf can you watch recorded events?

yes when watching as MP4. it acts weird as MJPEG, but i'm not sure if it's my setup.

@abishai
Copy link
Contributor Author

abishai commented Jan 12, 2023

@connortechnology May I ask you another offtopic question here ? Some of locales in lang looks suspicious. For example, en_gb.php contains LC_TIME=en_GB.utf8 . I think this is incorrect, it should be UTF-8.

@abishai
Copy link
Contributor Author

abishai commented Jan 12, 2023

nm, it's fixed already.

@abishai
Copy link
Contributor Author

abishai commented Jan 12, 2023

@hjf Received the patch, will try it. Thanks!

@VVD
Copy link

VVD commented Jan 14, 2023

Is 1.36.32 has deprecated warnings fixed?

I don't see them anymore.

Can you check that Record mode works as well? I've experienced watchdog issue for every monitor in Record mode in 1.36.19. But, as I doubt that this one FreeBSD specific, maybe it's fixed in 1.36.32

I'm use Modect with Camera Passthrough.

After I install 1.36.12 and configure 3 cams I got #3414, then added ram 16GB+swap 16GB, but OOM was almost after every alarm. Then it disappeared and I don't know what helped. It work fine for 3 days with a lot of alarms even with 4GB of ram without use of swap.
Now I update to 1.36.32 and got same on one cam - every alarm = OOM.
Set Maximum Image Buffer Size (frames) to 200 and OOM replaced with messages in log:

Jan 14 18:14:45 cctv zmwatch[78559]: WAR [Analysis daemon for 2 Cam-2 needs restarting, time since last analysis 48 seconds (1673709285-1673709237)]
Jan 14 18:14:46 cctv zmc_m2[96548]: WAR [zmc_m2] [Unable to get starting packet lock]
Jan 14 18:14:46 cctv zmc_m2[96548]: ERR [zmc_m2] [ALARM but no event]
Jan 14 18:14:57 cctv zmdc[78510]: WAR ['zmc -m 2' has not stopped at 23/01/14 18:14:57 after 10 seconds. Sending KILL to pid 96548]
Jan 14 18:18:14 cctv zmc_m2[98348]: WAR [zmc_m2] [You have set the max video packets in the queue to 200. The queue is full. Either Analysis is not keeping up or your camera's keyframe interval 21 is larger than this setting.]
Jan 14 18:18:16 cctv zmc_m2[98348]: WAR [zmc_m2] [Found locked packet when trying to free up video packets. This basically means that decoding is not keeping up.]

Analysis FPS 2, FPS from cam 10, video stream from cams 2048x1536 h264.

Top look like this most time:

Mem: 1951M Active, 260K Inact, 1277M Laundry, 693M Wired, 392M Buf, 20M Free
Swap: 16G Total, 841M Used, 15G Free, 5% Inuse, 4096B In, 3840K Out

  PID USERNAME    THR PRI NICE   SIZE    RES STATE    C   TIME    WCPU COMMAND
   11 root          3 155 ki31     0B    48K RUN      0  58,2H 244,15% [idle]
96282 www           4  20    0   687M   358M select   0   7:25  20,12% /usr/local/bin/zmc -m 3
96266 www           4  20    0   655M   362M select   0   7:26  19,05% /usr/local/bin/zmc -m 1
98348 www           4  20    0  3389M  2455M select   1   1:48  15,86% /usr/local/bin/zmc -m 2

@abishai
Copy link
Contributor Author

abishai commented Jan 14, 2023

Analysys FPS (and other ZM FPS settings) are very dangerous. I think they should be unset...

@abishai
Copy link
Contributor Author

abishai commented Jan 14, 2023

Is ajax request works for you in monitor view ? (Request that loads monitor alarm state and fps). It throws HTTP=500, something is wrong with semaphores again, however I have semaphore php extensions.

@hjf
Copy link

hjf commented Jan 14, 2023

I have had OOM but I think they are related to my server not being able to compress h.264 fast enough. but I tried to revert back to JPEG and the MJPEG recordings don't play. there is a segfault in logs.

@abishai
Copy link
Contributor Author

abishai commented Jan 14, 2023

Well, looks like 1.36.12 is the last one that works under FreeBSD.
1.36.32 has the same issue that stopped updating to 1.36.19

Any attempt to write stream produces zmc crash. While monitor in detect mode and detection not triggered everything looks OK. The fasted way to test is just put monitor in record mode.

I've tried to lower FPS and resolution, so it's not 'decoding not keeping up' and single zmc instance produces 0.3 load (= less than 1 core)



1/14/23, 6:50:22 PM GMT+3 | zmdc |   | 12729 | ERR | 'zmc -m 6' exited abnormally, exit status 11 | zmdc.pl | -
-- | -- | -- | -- | -- | -- | -- | --
1/14/23, 6:50:22 PM GMT+3 | zmc_m6 |   | 583650 | ERR | Signal address is 0x125, from 0x27f012 | zm_signal.cpp | 80
1/14/23, 6:50:22 PM GMT+3 | zmc_m6 |   | 583650 | ERR | Got signal 11 (Segmentation fault), crashing | zm_signal.cpp | 50
1/14/23, 6:49:54 PM GMT+3 | zmc_m6 |   | 569575 | WAR | Found locked packet when trying to free up video packets. This basically means that decoding is not keeping up. | zm_packetqueue.cpp | 156
1/14/23, 6:49:54 PM GMT+3 | zmc_m6 |   | 569575 | WAR | You  have set the max video packets in the queue to 120. The queue is full.  Either Analysis is not keeping up or your camera's keyframe interval 0  is larger than this setting. | zm_packetqueue.cpp | 139
1/14/23, 6:48:57 PM GMT+3 | zmdc |   | 12729 | WAR | 'zmc -m 6' has not stopped at 23/01/14 18:48:57 after 10 seconds. Sending KILL to pid 31612 | zmdc.pl | -
1/14/23, 6:48:46 PM GMT+3 | zmc_m6 |   | 582186 | WAR | Unable to get starting packet lock | zm_monitor.cpp | 2692
1/14/23, 6:48:46 PM GMT+3 | zmwatch |   | 12864 | WAR | Analysis daemon for 6 Monitor-6 needs restarting, time since last analysis 47 seconds (1673711326-1673711279) | zmwatch.pl | -
1/14/23, 6:44:07 PM GMT+3 | zmc_m6 |   | 101695 | WAR | Found locked packet when trying to free up video packets. This basically means that decoding is not keeping up. | zm_packetqueue.cpp | 156
1/14/23, 6:44:07 PM GMT+3 | zmc_m6 |   | 101695 | WAR | You  have set the max video packets in the queue to 120. The queue is full.  Either Analysis is not keeping up or your camera's keyframe interval 0  is larger than this setting. | zm_packetqueue.cpp | 139
1/14/23, 6:43:22 PM GMT+3 | zmdc |   | 12729 | ERR | 'zmc -m 6' exited abnormally, exit status 11 | zmdc.pl | -
1/14/23, 6:43:22 PM GMT+3 | zmc_m6 |   | 581980 | ERR | Signal address is 0xbd, from 0x27f012 | zm_signal.cpp | 80
1/14/23, 6:43:22 PM GMT+3 | zmc_m6 |   | 581980 | ERR | Got signal 11 (Segmentation fault), crashing | zm_signal.cpp | 50
1/14/23, 6:43:21 PM GMT+3 | zmc_m6 |   | 276253 | WAR | Found locked packet when trying to free up video packets. This basically means that decoding is not keeping up. | zm_packetqueue.cpp | 156
1/14/23, 6:43:21 PM GMT+3 | zmc_m6 |   | 276253 | WAR | You  have set the max video packets in the queue to 120. The queue is full.  Either Analysis is not keeping up or your camera's keyframe interval 0  is larger than this setting. | zm_packetqueue.cpp | 139
1/14/23, 6:42:41 PM GMT+3 | zmdc |   | 12729 | ERR | 'zmc -m 6' exited abnormally, exit status 11 | zmdc.pl | -
1/14/23, 6:42:41 PM GMT+3 | zmc_m6 |   | 581790 | ERR | Signal address is 0xdd, from 0x27f012 | zm_signal.cpp | 80
1/14/23, 6:42:41 PM GMT+3 | zmc_m6 |   | 581790 | ERR | Got signal 11 (Segmentation fault), crashing | zm_signal.cpp | 50

signal 11 is always comes after 'locked packed' warning. Probably, memory corruption after zmc memory exhausted.

@VVD
Copy link

VVD commented Jan 14, 2023

Analysys FPS (and other ZM FPS settings) are very dangerous. I think they should be unset...

Recommendations got this #3414.

Is ajax request works for you in monitor view ? (Request that loads monitor alarm state and fps). It throws HTTP=500, something is wrong with semaphores again, however I have semaphore php extensions.

Montage preview? Or what?

php81-ctype-8.1.14             The ctype shared extension for php
php81-gd-8.1.14                The gd shared extension for php
php81-intl-8.1.14              The intl shared extension for php
php81-opcache-8.1.14           The opcache shared extension for php
php81-pdo-8.1.14               The pdo shared extension for php
php81-pdo_mysql-8.1.14         The pdo_mysql shared extension for php
php81-pecl-APCu-5.1.22         APC User Caching
php81-session-8.1.14           The session shared extension for php
php81-sockets-8.1.14           The sockets shared extension for php

signal 11 is always comes after 'locked packed' warning. Probably, memory corruption after zmc memory exhausted.

Where do you get this log? What file name?

Oh, from menu Log:

1/14/23, 7:01:36 PM GMT+3 | zmc_m2 |   | 100074 | WAR | Found locked packet when trying to free up video packets. This basically means that decoding is not keeping up. | zm_packetqueue.cpp | 156
-- | -- | -- | -- | -- | -- | -- | --
1/14/23, 7:01:35 PM GMT+3 | zmc_m2 |   | 100074 | INF | Cam-2: 4700 - Capturing at 10.02 fps, capturing bandwidth 50062bytes/sec Analysing at 1.60 fps | zm_monitor.cpp | 1681
1/14/23, 7:01:34 PM GMT+3 | zmc_m2 |   | 100074 | WAR | You  have set the max video packets in the queue to 200. The queue is full.  Either Analysis is not keeping up or your camera's keyframe interval 21  is larger than this setting. | zm_packetqueue.cpp | 139

@abishai
Copy link
Contributor Author

abishai commented Jan 14, 2023

Montage preview? Or what?

When you click on monitor name ?view=watch

@VVD
Copy link

VVD commented Jan 14, 2023

Montage preview? Or what?

When you click on monitor name ?view=watch

I see video, but apache spam php errors in error_log:

[Sat Jan 14 19:19:27.173855 2023] [php:warn] [pid 99226] [client MYIP:10718] PHP Warning:  fopen(/usr/local/www/zoneminder/includes/functions.php.sem.590549): Failed to open stream: Permission denied in /usr/local/www/zoneminder/includes/functions.php on line 2239, referer: http://SERVER/zm/index.php?view=watch&mid=1
[Sat Jan 14 19:19:27.173914 2023] [php:error] [pid 99226] [client MYIP:10718] PHP Fatal error:  Uncaught TypeError: flock(): Argument #1 ($stream) must be of type resource, bool given in /usr/local/www/zoneminder/includes/functions.php:2242\nStack trace:\n#0 /usr/local/www/zoneminder/includes/functions.php(2242): flock(false, 2)\n#1 /usr/local/www/zoneminder/ajax/stream.php(28): sem_acquire(false, 1)\n#2 /usr/local/www/zoneminder/index.php(269): require_once('/usr/local/www/...')\n#3 {main}\n  thrown in /usr/local/www/zoneminder/includes/functions.php on line 2242, referer: http://SERVER/zm/index.php?view=watch&mid=1

Ofc process with owner www can't open /usr/local/www/zoneminder/includes/functions.php.sem.590549:

ls -l /usr/local/www/zoneminder/includes/
total 352
-rw-r--r--  1 root  wheel   7367 Nov 18 22:21 Control.php
-rw-r--r--  1 root  wheel  23610 Nov 18 22:21 Event.php
-rw-r--r--  1 root  wheel  21270 Nov 18 22:21 Filter.php
-rw-r--r--  1 root  wheel  14208 Nov 18 22:21 FilterTerm.php
-rw-r--r--  1 root  wheel   1162 Nov 18 22:21 Frame.php
-rw-r--r--  1 root  wheel   7225 Nov 18 22:21 Group.php
-rw-r--r--  1 root  wheel    565 Nov 18 22:21 Group_Monitor.php
-rw-r--r--  1 root  wheel  23994 Nov 18 22:21 Monitor.php
-rw-r--r--  1 root  wheel    564 Nov 18 22:21 MontageLayout.php
-rw-r--r--  1 root  wheel  16434 Nov 18 22:21 Object.php
-rw-r--r--  1 root  wheel   4234 Nov 18 22:21 Server.php
-rw-r--r--  1 root  wheel   1954 Nov 18 22:21 Snapshot.php
-rw-r--r--  1 root  wheel   5129 Nov 18 22:21 Storage.php
-rw-r--r--  1 root  wheel   1464 Nov 18 22:21 User.php
-rw-r--r--  1 root  wheel   1686 Nov 18 22:21 Zone.php
drwxr-xr-x  2 root  wheel   1024 Jan 14 16:58 actions
-rw-r--r--  1 root  wheel  17024 Nov 18 22:21 auth.php
-rw-r--r--  1 root  wheel   9610 Jan 14 16:49 config.php
-rw-r--r--  1 root  wheel  27654 Nov 18 22:21 control_functions.php
drwxr-xr-x  2 root  wheel    512 Jan 14 16:58 csrf
-rw-r--r--  1 root  wheel  11257 Nov 18 22:21 database.php
-rw-r--r--  1 root  wheel  77700 Nov 18 22:21 functions.php
-rw-r--r--  1 root  wheel   2212 Nov 18 22:21 lang.php
-rw-r--r--  1 root  wheel  16647 Nov 18 22:21 logger.php
-rw-r--r--  1 root  wheel   6211 Nov 18 22:21 session.php

chown www /usr/local/www/zoneminder/includes fixed this error, but WHY it try to create files in dir with php files?!

@abishai
Copy link
Contributor Author

abishai commented Jan 14, 2023

Probably some temp directory or config is not set. On another way, php issues are not so serious. But zmc crash is. All I know version 1.36.12 works, 1.36.32 (and as I know for sure - 1.36.19) has zmc issue. So we can't update the port.

@VVD
Copy link

VVD commented Jan 17, 2023

Every 10 minutes:

2023-01-17 17:51:40 | zmc_m2 |   | 154295 | ERR | Signal address is 0xaa, from 0x28d612 | zm_signal.cpp | 80
-- | -- | -- | -- | -- | -- | -- | --
2023-01-17 17:51:40 | zmc_m2 |   | 154295 | ERR | Got signal 11 (Segmentation fault), crashing | zm_signal.cpp | 50
2023-01-17 17:51:40 | zmc_m2 |   | 147930 | WAR | Found locked packet when trying to free up video packets. This basically means that decoding is not keeping up. | zm_packetqueue.cpp | 156
-- | -- | -- | -- | -- | -- | -- | --
2023-01-17 17:51:38 | zmc_m2 |   | 147930 | WAR | You  have set the max video packets in the queue to 100. The queue is full.  Either Analysis is not keeping up or your camera's keyframe interval 21  is larger than this setting. | zm_packetqueue.cpp | 139

1.36.32 buggy.

@connortechnology
Copy link
Member

In the directions linked to, some additions/comments:

You missed the step where you actually start fcgiwrap
In the nginx config, should index index.php not end in a semi colon?

I have my system up and running with 1.36.32, It has some serious issues. First off, it seems to be trying to save event data to /var/db/zoneminder/events but that dir didn't get created/ownership assigned.

@VVD
Copy link

VVD commented Jan 17, 2023

@abishai
Copy link
Contributor Author

abishai commented Jan 17, 2023

@connortechnology
You are right, manual can be improved.
As for directory, I was sure ZM creates it, providing it owns /var/db/zoneminder. I'll add directory.

Is port runs for you or you need some help? I believe, the best way to be sure everything is OK is try 1.36.12 first. It runs smoothly.

@connortechnology
Copy link
Member

Have it installed and running, but it is crashing. Working on it.

@connortechnology
Copy link
Member

How can I get the debug symbols from ports ?

@connortechnology
Copy link
Member

I have solved the crash I was experiencing. Something I had fixed in master. I will release 1.36.33 this week with the fix.
779ae50

@abishai
Copy link
Contributor Author

abishai commented Jan 17, 2023

How can I get the debug symbols from ports ?

echo WITH_DEBUG_PORTS= multimedia/zoneminder > /etc/make.conf

@abishai
Copy link
Contributor Author

abishai commented Jan 17, 2023

For me, situation doesn't improve with the patch. Monitors in record and mocord mode are crashing. Modect mode works outside of alarm state.

@VVD Is situation improved for you? Maybe I connected dots in wrong way with the port.

1/17/23, 11:22:55 PM GMT+3 | zmdc |   | 88869 | ERR | 'zmc -m 6' exited abnormally, exit status 11 | zmdc.pl | -
-- | -- | -- | -- | -- | -- | -- | --
1/17/23, 11:22:55 PM GMT+3 | zmc_m6 |   | 715820 | ERR | Signal address is 0xdb, from 0x27f012 | zm_signal.cpp | 80
1/17/23, 11:22:55 PM GMT+3 | zmc_m6 |   | 715820 | ERR | Got signal 11 (Segmentation fault), crashing | zm_signal.cpp | 50
1/17/23, 11:22:53 PM GMT+3 | zmdc |   | 88869 | ERR | 'zmc -m 8' exited abnormally, exit status 11 | zmdc.pl | -
1/17/23, 11:22:52 PM GMT+3 | zmc_m8 |   | 715886 | ERR | Signal address is 0xa5, from 0x27f012 | zm_signal.cpp | 80
1/17/23, 11:22:52 PM GMT+3 | zmc_m8 |   | 715886 | ERR | Got signal 11 (Segmentation fault), crashing | zm_signal.cpp | 50
1/17/23, 11:22:48 PM GMT+3 | zmc_m8 |   | 586423 | WAR | Found locked packet when trying to free up video packets. This basically means that decoding is not keeping up. | zm_packetqueue.cpp | 156
1/17/23, 11:22:48 PM GMT+3 | zmc_m8 |   | 586423 | WAR | You  have set the max video packets in the queue to 80. The queue is full.  Either Analysis is not keeping up or your camera's keyframe interval 0  is larger than this setting. | zm_packetqueue.cpp | 139
1/17/23, 11:22:40 PM GMT+3 | zmwatch |   | 88989 | WAR | Restarting capture daemon for 5 Monitor-5, time since last capture 53 seconds (1673986960-1673986907) | zmwatch.pl | -
1/17/23, 11:22:35 PM GMT+3 | zmc_m6 |   | 523438 | WAR | Found locked packet when trying to free up video packets. This basically means that decoding is not keeping up. | zm_packetqueue.cpp | 156
1/17/23, 11:22:35 PM GMT+3 | zmc_m6 |   | 523438 | WAR | You  have set the max video packets in the queue to 80. The queue is full.  Either Analysis is not keeping up or your camera's keyframe interval 0  is larger than this setting. | zm_packetqueue.cpp | 139
1/17/23, 11:22:09 PM GMT+3 | zmwatch |   | 88989 | WAR | Restarting capture daemon for 6 Monitor-6, time since last capture 47 seconds (1673986929-1673986882) | zmwatch.pl | -
1/17/23, 11:22:01 PM GMT+3 | zmc_m4 |   | 610469 | WAR | Found locked packet when trying to free up video packets. This basically means that decoding is not keeping up. | zm_packetqueue.cpp | 156
1/17/23, 11:21:59 PM GMT+3 | zmc_m4 |   | 610469 | WAR | You  have set the max video packets in the queue to 80. The queue is full.  Either Analysis is not keeping up or your camera's keyframe interval 9  is larger than this setting. | zm_packetqueue.cpp | 139
1/17/23, 11:21:49 PM GMT+3 | zmdc |   | 88869 | ERR | 'zmc -m 5' exited abnormally, exit status 11 | zmdc.pl | -
1/17/23, 11:21:48 PM GMT+3 | zmc_m5 |   | 715360 | ERR | Signal address is 0x181, from 0x27f012 | zm_signal.cpp | 80
1/17/23, 11:21:48 PM GMT+3 | zmc_m5 |   | 715360 | ERR | Got signal 11 (Segmentation fault), crashing | zm_signal.cpp | 50
1/17/23, 11:21:47 PM GMT+3 | zmdc |   | 88869 | ERR | 'zmc -m 8' exited abnormally, exit status 11 | zmdc.pl | -
1/17/23, 11:21:46 PM GMT+3 | zmc_m8 |   | 715593 | ERR | Signal address is 0xb8, from 0x27f012 | zm_signal.cpp | 80
1/17/23, 11:21:46 PM GMT+3 | zmc_m8 |   | 715593 | ERR | Got signal 11 (Segmentation fault), crashing | zm_signal.cpp | 50

connortechnology pushed a commit that referenced this issue Jan 17, 2023
… of the time, don't dereference it. When falling back to read/write, just read in chunks of 4096, because I don't know how to make llvm use c99 dynamic arrays. Check for HAVE_SENDFILE. Fixes #3505
@connortechnology
Copy link
Member

I can now view jpeg saved events after applying 8300a7b . What I am seeing now is the that opening a new event is taking forever. .2 seconds to do the event insert into the db. So the capture queues fill up.

Also, decoding is not keeping up. I don't know why freebsd is so slow for decoding. It can't keep up with a 1080p stream in this vm. Similar Ubuntu vm's have no trouble.

@abishai
Copy link
Contributor Author

abishai commented Jan 18, 2023

I have 779ae50 applied only.

The decoding is not keeping up since 1.32.16. Currently, my installation contains 12 5MP cameras on 4fps and they consume 4-5 cores. The same warnings exist in 1.36.12 zm_packetqueue.cpp but logs are silent.

I'll try to enable debug logs then to see timings.

@abishai
Copy link
Contributor Author

abishai commented Jan 18, 2023

zmc.log
Attached the log from 1.36.12 with DB1 for monitor in Record state. Is it keeping up? I don't see warnings and queue size looks stable.

Maybe you know better where to look. ZM writes quite a lot :)
I'm going to repeat with 1.36.32 to compare, should I stay on DB1 or increase verbosity further or configure more components?

@VVD
Copy link

VVD commented Jan 18, 2023

Also, decoding is not keeping up. I don't know why freebsd is so slow for decoding. It can't keep up with a 1080p stream in this vm. Similar Ubuntu vm's have no trouble.

It's not "FreeBSD slow". On both OSes ZM use ffmpeg. 3M (2048x1536) cam 10 fps h264 - decoding and analyzing "eat" ~20-25% of 1 core of Core i7 920@3.1GHz in VirtualBox vm.
It's bug in recent ZM. And abishai searching it.

@VVD
Copy link

VVD commented Jan 18, 2023

For me, situation doesn't improve with the patch. Monitors in record and mocord mode are crashing. Modect mode works outside of alarm state.

@VVD Is situation improved for you? Maybe I connected dots in wrong way with the port.

I can't apply patch:

/tmp/work/usr/ports/multimedia/zoneminder/work/zoneminder-1.36.32/src/zm_eventstream.cpp:580:52: error: use of undeclared identifier 'MSG_DONTWAIT'
  if ( sendto(sd, &status_msg, sizeof(status_msg), MSG_DONTWAIT, (sockaddr *)&rem_addr, sizeof(rem_addr)) < 0 ) {
                                                   ^

And it's after return

#ifdef __cplusplus
extern "C" {
#endif

Too much changes from 1.36.32.
Update port to build from GH commit instead of a tarball it's long…

@VVD
Copy link

VVD commented Jan 18, 2023

Returned back on 1.36.12.
I'll check tomorrow if it's stable.

@abishai
Copy link
Contributor Author

abishai commented Jan 18, 2023

Too much changes from 1.36.32. Update port to build from GH commit instead of a tarball it's long…

I've applied https://github.com/ZoneMinder/zoneminder/commit/779ae5051e43629189b7f6780978676a7c6a21ca.patch to 1.36.32 without any issues.

@VVD
Copy link

VVD commented Jan 18, 2023

Oh.
I tried to apply this one: 8300a7b instead :-D

@connortechnology
Copy link
Member

I have pushed my latest fixes to release-1.36 branch. Compiles and runs perfectly for me now.

@VVD
Copy link

VVD commented Jan 30, 2023

I have pushed my latest fixes to release-1.36 branch. Compiles and runs perfectly for me now.

Your patches for port multimedia/zoneminder or for zoneminder itself?

@connortechnology
Copy link
Member

ZoneMinder itself.

@abishai
Copy link
Contributor Author

abishai commented Feb 24, 2023

Hello, I'd like to return to port upgrade.
Can I test 1.36.33 ? It looks like relevant changes was merged from release-1.36, right?

@abishai
Copy link
Contributor Author

abishai commented Feb 24, 2023

1.36.33 shows signs of flawless working ^^ I see no packet locked logs or any other warnings. Recording and detection works as well.

Huge thanks to @connortechnology and everyone who helped to test ZM.

I'll leave updated ZM to work for a day to see if I find something.

@VVD
Copy link

VVD commented Apr 17, 2023

Just for information: updated to 1.36.33 and it work fine now.
Require "sudo -u www zmupdate.pl -f".

@connortechnology
Copy link
Member

@abishai I think we can close this now, right? Also, I've been looking at an openbsd port. Which got me thinking the freebsd port stuff should be included here under the distros directory maybe. What do you think?

@abishai
Copy link
Contributor Author

abishai commented Apr 26, 2023

@connortechnology Yes, I suppose this one can be closed.
But do we have enough content for distro directory? We have ~5 patches to build ZM and read me (a little bit dated, as mysql57 is EOL - I'll update it when migrate).

Probably, the only candidate is rc.d script https://github.com/freebsd/freebsd-ports/blob/main/multimedia/zoneminder/files/zoneminder.in but I doubt it worth a dedicated directory.

@connortechnology
Copy link
Member

So... I just think keeping everything in one spot is the way to go, but on the other hand, I've thought about stripping out the distro dir into it's own repos, which is certainly the debian way to do things.

So I don't know. What I do think is that there should be both a stable port (1.36) and a master port.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants