You are here: Foswiki>Tasks Web>Item14221 (31 Jan 2018, VadimBelman)Edit Attach

Item14221: Regression: writing to STDERR is broken under FastCGI

Priority: Urgent
Current State: Closed
Released In: 2.1.3
Target Release: n/a
Applies To: Engine
Component: FastCGIEngineContrib
Branches: master Release02x01 Item14380 Item14537
Reported By: MichaelDaum
Waiting For:
Last Change By: VadimBelman
There is a change committed as part of Item14205 which now stops STDERR from being used as a poor man's debugging tool.

This commit seems to have broken it.

The comments in the engine code recommend to write to $engine->{fhERR} instead. This is not a viable solution. die() and all use STDERR and we need this output in the webserver's error.log.

Even the defaults to still use STDERR as usual don't seem to work.

-- MichaelDaum - 18 Nov 2016

This breaks my @keys = $request->param() for POSTed data as well. I don't understand the code but reverting this:

diff --git a/core/lib/Foswiki/Engine/ b/core/lib/Foswiki/Engine/
index 2d87e25..5fbca2b 100644
--- a/core/lib/Foswiki/Engine/
+++ b/core/lib/Foswiki/Engine/
@@ -234,7 +234,7 @@ sub prepareBody {
     # as breaking uploads (though cdot believes this is because of the
     # deprecated dual nature of param delivering lightweight file handles,
     # and it would probably work in Foswiki. Just not tried it)
-    my $cgi = new CGI( $this->{fhIN} );
+    my $cgi = new CGI();
     my $err = $cgi->cgi_error;
     throw Foswiki::EngineException( $1, $2 )

and this

diff --git a/FastCGIEngineContrib/lib/Foswiki/Engine/ b/FastCGIEngineContrib/lib/Foswiki/Engine/
index 2808d3c..8d0e779 100644
--- a/FastCGIEngineContrib/lib/Foswiki/Engine/
+++ b/FastCGIEngineContrib/lib/Foswiki/Engine/
@@ -66,12 +66,7 @@ sub run {
     $args ||= {};
-    # Prepare output handles for FastCGI.
-    $this->{$_} = IO::Handle->new foreach qw(fhIN fhOUT fhERR);
-    # This is a little trick to make all `print STDERR' clauses send their
-    # output to the log file. May not work for spawned processes.
-    STDERR->fdopen($this->{fhERR}->fileno, "w");
-    my $r = FCGI::Request( $this->{fhIN}, $this->{fhOUT}, $this->{fhERR}, \%ENV, $sock,
+    my $r = FCGI::Request( \*STDIN, \*STDOUT, \*STDERR, \%ENV, $sock,
     my $manager;
@@ -189,12 +184,11 @@ sub preparePath {
     $ENV{PATH_INFO} =~ s#^$Foswiki::cfg{ScriptUrlPath}/*#/#
       if ( $ENV{PATH_INFO} && defined $Foswiki::cfg{ScriptUrlPath} );
-    return $this->SUPER::preparePath();
+    return $this->SUPER::preparePath(@_);
 sub write {
-    my $this = shift;
-    syswrite $this->{fhOUT}, $_[0];
+      syswrite STDOUT, $_[1];

fixes it again. Before reverting, please comment on above code changes. Obviously some unit tests are missing that iterate over POSTed params.

Steps to reproduce:

  • add my @keys = $request->param(); print STDERR "keys=@keys\n"; somewhere in the code
  • do a file upload

Either you don't get an error in your webserver's error.logs. or STDERR should look wild due to the uploaded payload in the POSTDATA being returned to the keys.

-- MichaelDaum - 18 Nov 2016

POST is fine again after f6350568d343, printing to STDERR is still broken. Maybe this is due to nginx and FastCGI::ProcManager being different than apache's mod_fcgi.

-- MichaelDaum - 22 Nov 2016

I was using apache 2.2 and mod_fcgid for testing.

-- VadimBelman - 24 Nov 2016

Setting to closed. This was never in a shipped release, so no need to document.

-- GeorgeClark - 05 Dec 2016
Topic revision: r11 - 31 Jan 2018, VadimBelman - This page was cached on 18 Feb 2018 - 09:18.

The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License