Loading ...
Sorry, an error occurred while loading the content.

PERL cgi script killed by apache on client abort

Expand Messages
  • prejf
    My upload script which uses upload hook works really nice. After the upload ends it writes some debug stuff to log file and sends some info to other host. When
    Message 1 of 10 , Mar 26, 2011
    • 0 Attachment
      My upload script which uses upload hook works really nice. After the upload ends it writes some debug stuff to log file and sends some info to other host.

      When client aborts the upload the reminder of the script after hook is not executed and i get an error in my apache log:

      [Sat Mar 26 14:53:09 2011] [error] [client xxx.xxx.xxx.xxx] (70014)End + of file found: Error reading request entity data, referer: http://lo +calhost/upload
      [download]

      I'm thinking its the fault of apache, because without abort the script works just fine. Does anyone have any clue about it ? The script:

      #!/usr/bin/perl -w use strict; use CGI; use warnings; use Digest::MD5 qw(md5_hex); use POSIX qw/ceil/; use POSIX 'setsid'; use LWP::Simple; $CGI::DISABLE_UPLOADS = 0; $CGI::POST_MAX = 1024 * 1024 * 2000000; our $php_exec = '/usr/bin/php'; our $www_root = 'www_root'; our $SERVER_NUMBER = '1'; our $pid = 666; our $data; our $first_hook = 1; our $sum_bytes = 0; our $approx_file_size = 0; our $original_filename = ""; our $storage_name = ""; our $db_path = "path where the file with number of stored files is"; our $upload_path = "path to storage folder"; our $debug_path = "path to log folder"; our $url = ''; our $content = ''; #zmienna identyfikująca urzytkownika wyciągnięta z +pola GET my $query_string = $ENV{QUERY_STRING}; my $sessid = $query_string; my $upload_session = $query_string; $sessid =~ m/userid=([0-9]+)/i; our $userid = $1; $upload_session =~ m/us=([a-zA-Z0-9]+)/i; our $upload_sess = $1; my $line = 0; #zmiana aktualnej ilości plików przechowywanych na serwerze open(UPLOAD_DB, "+<", $db_path."upload_db") or die "Cannot open : +$!"; flock(UPLOAD_DB, 2); $line = <UPLOAD_DB>; our $filenumber = $line + 1; seek(UPLOAD_DB, 0, 0); truncate(UPLOAD_DB, 0); print UPLOAD_DB $filenumber; close UPLOAD_DB; our $dir = ceil($filenumber/5); unless (-d $upload_path.$dir) { mkdir $upload_path.$dir, 0777; #print $!; } $upload_path = $upload_path.$dir."/"; our $logfile = $debug_path."hook_debug.txt"; our $q = CGI->new(\&hook, $logfile, 0); sub hook { our ($filename, $buffer, $bytes_read, $logfile) = @_; + $sum_bytes = $bytes_read; if($first_hook) { $approx_file_size = $ENV{CONTENT_LENGTH}; #print $approx_file_size.'\n<br />'; $approx_file_size -= 197; $original_filename = $filename; $filename =~ s/^\s+|\s+$//g ; $storage_name = md5_hex($filename."salt666".$filenumbe +r); open(UPLOADFILE, ">>", $upload_path.$storage_name ); chmod 0777, $upload_path.$storage_name; binmode UPLOADFILE; print UPLOADFILE $buffer; close UPLOADFILE; $first_hook = 0; }else{ open(DEBUG, ">>", $debug_path."abort_debug.txt" ); binmode DEBUG; print DEBUG "BR: "; print DEBUG "$bytes_read\n"; close DEBUG; open(UPLOADFILE, ">>", $upload_path.$storage_name ); binmode UPLOADFILE; print UPLOADFILE $buffer; close UPLOADFILE; if (($buffer eq '') == 1) { unlink($upload_path.$storage_name); open(DEBUG, ">>", $debug_path."abort_debug.txt" ); binmode DEBUG; print DEBUG "error file upload aborted\n"; close DEBUG; exit 0; } } } open(DEBUG, ">>", $debug_path."end_debug.txt" ); binmode DEBUG; print DEBUG "END\n#\n"; close DEBUG; print "Content-type: text/html\n\n END"; exit;
    • merlyn@stonehenge.com
      ... prejf I m thinking its the fault of apache, because without abort the prejf script works just fine. Does anyone have any clue about it ? In general, if
      Message 2 of 10 , Mar 26, 2011
      • 0 Attachment
        >>>>> "prejf" == prejf <przemek@...> writes:

        prejf> I'm thinking its the fault of apache, because without abort the
        prejf> script works just fine. Does anyone have any clue about it ?

        In general, if the client goes away, and the script generates output,
        Apache will send a SIGPIPE signal to the script. By default, this
        terminates the script (which is usually a good thing). If you have to
        perform tasks *after* the client might have gone away, you'll need to
        fork and run the task in the background.

        And now for my normal PSA:

        **************************************************
        *
        * THIS IS NOT THE OFFICIAL perl BEGINNERS GROUP.
        *
        * The official one is at beginners@..., with instructions on how to
        * join at http://lists.perl.org/list/beginners.html.
        *
        * You'll get far better response there, not to say you won't get *any* here.
        *
        **************************************************

        And in fact, there's a list just for beginners-cgi, named thusly.

        --
        Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
        <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
        Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
        See http://methodsandmessages.posterous.com/ for Smalltalk discussion
      • prejf
        I tried forking and run the upload hook in the child process. Tried detaching it from parent with setsid. But it was killed anyway. I could fork and make only
        Message 3 of 10 , Mar 27, 2011
        • 0 Attachment
          I tried forking and run the upload hook in the child process. Tried detaching it from parent with setsid. But it was killed anyway. I could fork and make only misc stuff in children but i would need to somehow catch the SIGPIPE signal so i know the upload was aborted. Is there a way to triger some action when the script recives a SIGPIPE ?

          --- In perl-beginner@yahoogroups.com, merlyn@... wrote:
          >
          > >>>>> "prejf" == prejf <przemek@...> writes:
          >
          > prejf> I'm thinking its the fault of apache, because without abort the
          > prejf> script works just fine. Does anyone have any clue about it ?
          >
          > In general, if the client goes away, and the script generates output,
          > Apache will send a SIGPIPE signal to the script. By default, this
          > terminates the script (which is usually a good thing). If you have to
          > perform tasks *after* the client might have gone away, you'll need to
          > fork and run the task in the background.
          >
          > And now for my normal PSA:
          >
          > **************************************************
          > *
          > * THIS IS NOT THE OFFICIAL perl BEGINNERS GROUP.
          > *
          > * The official one is at beginners@..., with instructions on how to
          > * join at http://lists.perl.org/list/beginners.html.
          > *
          > * You'll get far better response there, not to say you won't get *any* here.
          > *
          > **************************************************
          >
          > And in fact, there's a list just for beginners-cgi, named thusly.
          >
          > --
          > Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
          > <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
          > Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
          > See http://methodsandmessages.posterous.com/ for Smalltalk discussion
          >
        • merlyn@stonehenge.com
          ... prejf I tried forking and run the upload hook in the child prejf process. Tried detaching it from parent with setsid. But it was prejf killed anyway. I
          Message 4 of 10 , Mar 27, 2011
          • 0 Attachment
            >>>>> "prejf" == prejf <przemek@...> writes:

            prejf> I tried forking and run the upload hook in the child
            prejf> process. Tried detaching it from parent with setsid. But it was
            prejf> killed anyway. I could fork and make only misc stuff in children
            prejf> but i would need to somehow catch the SIGPIPE signal so i know
            prejf> the upload was aborted. Is there a way to triger some action when
            prejf> the script recives a SIGPIPE ?

            "perldoc perlipc" has all the details of catching signals.

            --
            Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
            <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
            Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
            See http://methodsandmessages.posterous.com/ for Smalltalk discussion
          • Wendell Hatcher
            Has anyone thought about building a Perl Application Server? If it has been done then can someone direct me to the application? Has [Non-text portions of this
            Message 5 of 10 , Mar 27, 2011
            • 0 Attachment
              Has anyone thought about building a Perl Application Server? If it has been done then can someone direct me to the application?






              Has
















              [Non-text portions of this message have been removed]
            • merlyn@stonehenge.com
              ... Wendell Has anyone thought about building a Perl Application Server? If Wendell it has been done then can someone direct me to the application? What
              Message 6 of 10 , Mar 27, 2011
              • 0 Attachment
                >>>>> "Wendell" == Wendell Hatcher <wlh1074@...> writes:

                Wendell> Has anyone thought about building a Perl Application Server? If
                Wendell> it has been done then can someone direct me to the application?

                What specific meaning are you attributing to those buzzwords?

                --
                Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
                <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
                Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
                See http://methodsandmessages.posterous.com/ for Smalltalk discussion
              • Wendell Hatcher
                Hi Randal,          if there would be interest in building a true Open-Source Perl Application Server Project on top of your Plack Server that has a
                Message 7 of 10 , Mar 28, 2011
                • 0 Attachment
                  Hi Randal,


                           if there would be interest in building a true Open-Source Perl Application Server Project on top of your Plack Server that has a messaging queues,clustering, database connections,web services along with other built in processes that make it easy to build,plug in and deploy a Perl Web Application?

                        This Application Server would also have ways to monitor the applications memory and thread processing. Please let me know your thoughts on this and if creating an Open-Source project doing this would make sense? I would love to be a part of it and assist with creating such an application. I think this Application Server should also take advantage of the native O.S.`s libraries and the Perl compilers ability to process code.

                  --- On Sun, 3/27/11, Randal L. Schwartz <merlyn@...> wrote:

                  From: Randal L. Schwartz <merlyn@...>
                  Subject: Re: [PBML] Perl Application Server????
                  To: "Wendell Hatcher" <wlh1074@...>
                  Cc: "prejf" <przemek@...>, perl-beginner@yahoogroups.com
                  Date: Sunday, March 27, 2011, 9:40 PM

                  >>>>> "Wendell" == Wendell Hatcher <wlh1074@...> writes:

                  Wendell> Has anyone thought about building a Perl Application Server? If
                  Wendell> it has been done then can someone direct me to the application?

                  What specific meaning are you attributing to those buzzwords?

                  --
                  Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
                  <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
                  Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
                  See http://methodsandmessages.posterous.com/ for Smalltalk discussion





                  [Non-text portions of this message have been removed]
                • merlyn@stonehenge.com
                  ... Wendell          if there would be interest in building a true Wendell Open-Source Perl Application Server Project on top of your Wendell Plack
                  Message 8 of 10 , Mar 28, 2011
                  • 0 Attachment
                    >>>>> "Wendell" == Wendell Hatcher <wlh1074@...> writes:

                    Wendell>          if there would be interest in building a true
                    Wendell> Open-Source Perl Application Server Project on top of your
                    Wendell> Plack Server that has a messaging queues,clustering, database
                    Wendell> connections,web services along with other built in processes
                    Wendell> that make it easy to build,plug in and deploy a Perl Web
                    Wendell> Application?

                    Wendell>       This Application Server would also have ways to monitor
                    Wendell> the applications memory and thread processing. Please let me
                    Wendell> know your thoughts on this and if creating an Open-Source
                    Wendell> project doing this would make sense? I would love to be a part
                    Wendell> of it and assist with creating such an application. I think
                    Wendell> this Application Server should also take advantage of the
                    Wendell> native O.S.`s libraries and the Perl compilers ability to
                    Wendell> process code.

                    This sounds like things that have been done over and over again in the
                    Perl world. Again, how much time have you spent looking at the CPAN for
                    the pieces you need?

                    --
                    Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777
                    0095 <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
                    Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
                    See http://methodsandmessages.posterous.com/ for Smalltalk discussion
                  • Wendell Hatcher
                    Randal,                 I was not aware that there is an PAR deployment Perl Application Server out there? I  sent out this email to gather
                    Message 9 of 10 , Mar 28, 2011
                    • 0 Attachment
                      Randal,

                                      I was not aware that there is an PAR deployment Perl Application Server out there? I  sent out this email to gather thoughts and see if it has already been done or if others would be interested in creating an Application Server. I haven't gone through the steps of gather modules and building out the project yet. I wanted to get the thoughts of others who if this is or is not a good idea?


                      -Wendell

                      --- On Mon, 3/28/11, Randal L. Schwartz <merlyn@...> wrote:

                      From: Randal L. Schwartz <merlyn@...>
                      Subject: Re: [PBML] Perl Application Server????
                      To: "Wendell Hatcher" <wlh1074@...>
                      Cc: "prejf" <przemek@...>, perl-beginner@yahoogroups.com
                      Date: Monday, March 28, 2011, 5:40 PM

                      >>>>> "Wendell" == Wendell Hatcher <wlh1074@...> writes:

                      Wendell>          if there would be interest in building a true
                      Wendell> Open-Source Perl Application Server Project on top of your
                      Wendell> Plack Server that has a messaging queues,clustering, database
                      Wendell> connections,web services along with other built in processes
                      Wendell> that make it easy to build,plug in and deploy a Perl Web
                      Wendell> Application?

                      Wendell>       This Application Server would also have ways to monitor
                      Wendell> the applications memory and thread processing. Please let me
                      Wendell> know your thoughts on this and if creating an Open-Source
                      Wendell> project doing this would make sense? I would love to be a part
                      Wendell> of it and assist with creating such an application. I think
                      Wendell> this Application Server should also take advantage of the
                      Wendell> native O.S.`s libraries and the Perl compilers ability to
                      Wendell> process code.

                      This sounds like things that have been done over and over again in the
                      Perl world.  Again, how much time have you spent looking at the CPAN for
                      the pieces you need?

                      --
                      Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777
                      0095 <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
                      Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
                      See http://methodsandmessages.posterous.com/ for Smalltalk discussion





                      [Non-text portions of this message have been removed]
                    • merlyn@stonehenge.com
                      ... Wendell                 I was not aware that there is an PAR deployment Wendell Perl Application Server out there? I  sent out this email
                      Message 10 of 10 , Mar 28, 2011
                      • 0 Attachment
                        >>>>> "Wendell" == Wendell Hatcher <wlh1074@...> writes:

                        Wendell>                 I was not aware that there is an PAR deployment
                        Wendell> Perl Application Server out there? I  sent out this email to
                        Wendell> gather thoughts and see if it has already been done or if
                        Wendell> others would be interested in creating an Application Server. I
                        Wendell> haven't gone through the steps of gather modules and building
                        Wendell> out the project yet. I wanted to get the thoughts of others who
                        Wendell> if this is or is not a good idea?

                        Stop using the word "Application Server".

                        Say exactly what you think it is. How would it interface with mod_perl?
                        How would it interface with other modules? How would it help
                        developers? What features does it supply, and what features does it
                        need from other pieces?

                        The problem is that "Application Server" can mean almost anything.

                        That's what I asked for you to do two mails ago. That'll help us
                        communicate.

                        --
                        Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777
                        0095 <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
                        Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
                        See http://methodsandmessages.posterous.com/ for Smalltalk discussion
                      Your message has been successfully submitted and would be delivered to recipients shortly.