Reputation: 6555
This is the related code, I shorted it as much as possible hopefully not excluding the error source.
DebugLogMsg is a printf like log file writing tool which can be considered as not causing the error.
//Some init stuff and smthng
while (1)
{
memset (&requestFcgx, 0, sizeof (requestFcgx));
iRet = FCGX_InitRequest (&requestFcgx, 0, 0);
DebugLogMsg ("FCGX_InitRequest() called!!\r\n");
if (iRet != 0)
{
DebugLogMsg ("FCGX_InitRequest failed, return val:%d!\r\n", iRet);
return NULL;
}
iRet = FCGX_Accept_r (&requestFcgx);
if (iRet != 0)
{
DebugLogMsg1 ("FCGX_Accept_r failed!\r\n");
continue;
}
char *foo = FCGX_GetParam("SOME_CUSTOM_VAL", requestFcgx.envp);
DebugLogMsg ("CustomParam:%s\r\n", foo);
do
{
//processing the request...
if (ERROR == TRUE)
{
DebugLogMsg ("FatalError!\r\n");
return NULL;
}
DebugLogMsg ("no errors occured!");
}
while (0);
FCGX_Finish_r (&requestFcgx);
DebugLogMsg ("Cleanup.... DONE!\r\n");
}
My problem is iRet = FCGX_Accept_r (&requestFcgx);
doesn't block every 2nd call, as it should. (at least I expect this function to it should be blocking)
As soon a request is sent by the webserver the Function releases, runs through the loop without any errors getting logged, calls the Finish, loops to the start of the loop body and when calling iRet = FCGX_Accept_r (&requestFcgx);
again, it returns instantly with iRet == 0
but the requestFcgx
structure seems to be invalid (what is to be expected as there was not even an aditional request initiated). The corresponding Log File contains for this process:
[Wed Apr 15 15:41:26 2015][Thread:0;0x802420040] FCGX_InitRequest() called!
----------------------------------------
[Wed Apr 15 15:41:26 2015][Thread:0;0x802420040] CustomParam:ExpectedStuff
[Wed Apr 15 15:41:26 2015][Thread:0;0x802420040] no errors occured!
[Wed Apr 15 15:41:26 2015][Thread:0;0x802420040] Cleanup.... DONE!
[Wed Apr 15 15:41:26 2015][Thread:0;0x802420040] FCGX_InitRequest() called!
----------------------------------------
[Wed Apr 15 15:41:26 2015][Thread:0;0x802420040] CustomParam:(null)
[Wed Apr 15 15:41:26 2015][Thread:0;0x802420040] FatalError!
//////////////////////////////
////////Protocol closed///////
//////////////////////////////
(Please someone edit the Logtext to be not formated as code, I don't know how to)
The Fatal error occures as the Request doesn't provide information and get shut down. the point is, why iRet = FCGX_Accept_r (&requestFcgx);
returns with 0
when it obvisiously failed? And in how far I have to consider this behaving, if it is expected to do so.
Upvotes: 0
Views: 1594
Reputation: 556
There are two issues -
FCGX_InitRequest(&requestFcgx, 0, 0)
needs to be called before entering the while(1)
loop.SIGPIPE signal can also cause this behaviour. Try ignoring it. Add this block to the start of your main()
function -
struct sigaction sa_ign;
sa_ign.sa_handler = SIG_IGN;
sa_ign.sa_flags = 0;
sigemptyset(&sa_ign.sa_mask);
sigaction(SIGPIPE, &sa_ign, NULL);
You mentioned that the app is multi-threaded. If so, you must also call FCGX_Init()
. Below is information from fcgiapp.h
header file -
/*
*----------------------------------------------------------------------
*
* FCGX_Init --
*
* Initialize the FCGX library. Call in multi-threaded apps
* before calling FCGX_Accept_r().
*
* Returns 0 upon success.
*
*----------------------------------------------------------------------
*/
DLLAPI int FCGX_Init(void);
Check this simple multi-threaded FastCGI application -
http://www.fastcgi.com/devkit/examples/threaded.c
Upvotes: 1