Motion - Bug Report 2005x 10x 29x 072220

BUG: jpeg image inconsistent after EVENT_FILECREATE

I have a script processing saved images and using the SECURITY SQL table as a queue. Once in a while , the images on disk are inconsistent (e.g. have 0 filesize, as reported by stat), although their path was inserted in the sql table by motion after they were saved . Waiting for 0.1s or so is sufficient to workaround the bug. There are 8 cameras on the system , so 8 threads of motion saving images at 2FPS.

A log-fragment from my script checking the security table queue: stat2 is 100ms after stat1, on the same file.
--
[  16308 2005-10-29 10:30: 0] found image /archive/20/2005/10/29/10/30/00-00.jpg id=4687821
[  16308 2005-10-29 10:30: 0] stat1: 770 6959188 33188 1 0 0 0 0 1130571000 1130571000 1130571000 131072 0
[  16308 2005-10-29 10:30: 0] stat2: 770 6959188 33188 1 0 0 0 34267 1130571000 1130571000 1130571000 131072 72
--
[  16308 2005-10-29 10:30:17] found image /archive/17/2005/10/29/10/30/17-00.jpg id=4687929
[  16308 2005-10-29 10:30:17] stat1: 770 6959253 33188 1 0 0 0 0 1130571017 1130571017 1130571017 131072 0
[  16308 2005-10-29 10:30:17] stat2: 770 6959253 33188 1 0 0 0 28028 1130571017 1130571017 1130571017 131072 56

Test case

my $sh = $dbh->prepare_cached("select id, filename from security order by id");
my $dh = $dbh->prepare_cached("delete from security where id=?");

while (1) {
  $sh->execute;
  while (my ($id,$path) = $sh->fetchrow_array) {
     write_log ("found image $path id=$id");
     if (! -s $path ) {#size is 0
         write_log ("stat1: ". join(" ", stat($path)));
         select(undef,undef,undef,0.1); #my way of sleeping ;)
         write_log ("stat2: ". join(" ", stat($path)));
     }
     my $err= process_image($path);
     $dh->execute($id) unless $err; #if the processing was ok, delete from queue
  }
  #empty queue, sleep a little so we don't kill the cpu
  select(undef,undef,undef,0.1); 
}

Environment

Motion version: 3.2.3
ffmpeg version:  
Shared libraries: postgresql
Server OS: Debian Sarge , 2.6.8-2-386 ,celeron2.6ghz, 256RAM, 8xbttv

-- BogdanLucaciu - 29 Oct 2005

Follow up

Fix record

I have ensured that Motion does not add records to SQL before the files have been saved to disk.

I cannot guarantee that the file system reports file sizes correct instantly and I am not sure how Motion can be "fixed" to help you on this one. We cannot let Motion wait.

You are welcome to reopen the bug if you find out something new.

-- KennethLavrsen - 18 Dec 2005
Topic revision: r2 - 18 Dec 2005, KennethLavrsen
Copyright © 1999-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Please do not email Kenneth for support questions (read why). Use the Support Requests page or join the Mailing List.
This website only use harmless session cookies. See Cookie Policy for details. By using this website you accept the use of these cookies.