You are here: Foswiki>Tasks Web>Item1823 (06 Jul 2010, MichaelDaum)Edit Attach

Item1823: Using FastCGIEngineContrib together with CODE_ENSCRIPT results in an error when viewing the topic

Priority: Normal
Current State: No Action Required
Released In:
Target Release: n/a
Applies To: Extension
Component: FastCGIEngineContrib
Reported By: IngoKappler
Waiting For:
Last Change By: MichaelDaum
Configure the system to use FastCGIEngineContrib with mod_fcgi or mod_fastcgi. Create a test topic with this content:

%CODE_ENSCRIPT{ lang="bash" }% #!/bin/bash

When trying to view this topic the following error shows up in the browser window::

Foswiki detected an internal error - please check your Foswiki logs and webserver logs for more information.

Can't locate object method "FILENO" via package "FCGI::Stream"

and in apache error log:

[Fri Jul 10 18:31:40 2009] [warn] mod_fcgid: stderr: Can't locate object method "FILENO" via package "FCGI::Stream" at /usr/share/perl5/IPC/ line 1118.

Encountered on Debian Lenny with apache2.

-- IngoKappler - 10 Jul 2009

Thanks for the bug report. Hopefully I will have time at the weekend to set up a Fast CGI environment and take a look.

Perhaps if I can remove the dependency on IPC::Run (Item8077) then this will no longer be an issue.

-- AndrewJones - 13 Jul 2009

I cannot reproduce this in my environment. What version of IPC::Run are you using? I am using 0.80.

-- AndrewJones - 07 Aug 2009

On my Debian is this installed: libipc-run-perl 0.80-2. There are also some other package named libipc-XXXXX-perl which are all not installed on my system.

I just retested and could still reproduce the issue:

Fcgi error.png

No issue with mod perl.png

Could it be helpful to look at the related apache-foswiki configuration? I could make it available to you.

-- IngoKappler - 07 Aug 2009

I get the same error when using BDB under FCGI. Here's a link that says that this is an FCGI problem (patch included):

--- /usr/lib/perl5/ 2009-08-11 19:16:38.000000000 +0200
+++ /usr/lib/perl5/      2009-08-11 19:16:41.000000000 +0200
@@ -134,7 +134,7 @@
 # Apparently some use fileno to determine if a filehandle is open,
 # so we might want to return a defined, but meaningless value.
 # An alternative would be to return the fcgi stream fd.
-# sub FILENO { -2 }
+sub FILENO { -2 }


-- MichaelDaum - 11 Aug 2009

Here's a patch that monkey patches FCGI::Stream via FastCGIEngineContrib:
--- lib/Foswiki/Engine/       (revision 4640)
+++ lib/Foswiki/Engine/       (working copy)
@@ -56,6 +56,13 @@
 *VERSION = \$Foswiki::Contrib::FastCGIEngineContrib::VERSION;
 *RELEASE = \$Foswiki::Contrib::FastCGIEngineContrib::RELEASE;

+# hack for perl libraries that use FILENO, alternatively patch
+  sub FILENO { -2 }
+  *FCGI::Stream::FILENO = \&FILENO;
 our $hupRecieved = 0;

Gilmar, do you think this is worth adding to FastCGIEngineContrib?

-- MichaelDaum - 11 Aug 2009

Reading FCGI code, I think that a semantically correct solution would be (untested):

    *FCGI::Stream::FILENO = sub {
        my ($stream) = @_;
        return fileno ${ $stream->{in} } if $stream->{type} == FCGI::FCGI_STDIN;
        return fileno ${ $stream->{out} }
          if $stream->{type} == FCGI::FCGI_STDOUT;
        return fileno ${ $stream->{err} }
          if $stream->{type} == FCGI::FCGI_STDERR;

But maybe this would cause more problems than it'd solve things... I think it needs careful tests to map side effects. The goal is: if a code calls fileno to figure out if the handle is open, any meaningless defined value is enough. But if the intention is to read/write to the handle directly (or to build another handle with dup), then it needs special attention. I don't know how Perl deals with this situation and it's what need to be tested.

-- GilmarSantosJr - 14 Aug 2009

This gets more and more important as the only reasonable Foswiki PageCache backend is BDB... which only works if we solve FILENO in FCGI. frown, sad smile

-- MichaelDaum - 21 Aug 2009

I want to see more cases where FILENO is required... but it's interesting to add the first workaround suggested to get things working.

How can I reproduce the issue with BDB?

-- GilmarSantosJr - 23 Aug 2009

Go to configure, enable the PageCache and enable the BDB backend.

-- MichaelDaum - 24 Aug 2009

It seems newer fcgi now does implement a FILENO. So hacking it in via FastCGIEngineContrib isnt necessary anymore. Infact, I get a "redefined" error with above patch.

-- MichaelDaum - 06 Jul 2010

ItemTemplate edit

Summary Using FastCGIEngineContrib together with CODE_ENSCRIPT results in an error when viewing the topic
ReportedBy IngoKappler
Codebase 1.0.6
SVN Range Foswiki-1.0.0, Thu, 08 Jan 2009, build 1878
AppliesTo Extension
Component FastCGIEngineContrib
Priority Normal
CurrentState No Action Required
TargetRelease n/a
I Attachment Action Size Date Who Comment
Fcgi_error.pngpng Fcgi_error.png manage 2 K 07 Aug 2009 - 12:44 IngoKappler Fcgi_error.png
No_issue_with_mod_perl.pngpng No_issue_with_mod_perl.png manage 3 K 07 Aug 2009 - 13:05 IngoKappler No_issue_with_mod_perl.png
Topic revision: r12 - 06 Jul 2010, MichaelDaum
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy