Bug 57685

Summary: Requests are denied while the mod_cgid daemon starts up
Product: Apache httpd-2 Reporter: Edward Lu <Chaosed0>
Component: mod_cgidAssignee: Apache HTTPD Bugs Mailing List <bugs>
Status: RESOLVED FIXED    
Severity: normal Keywords: FixedInTrunk, PatchAvailable
Priority: P2    
Version: 2.5-HEAD   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Attachments: Delay cgi requests made before the cgid daemon has started
Delay cgi requests made before the cgid daemon has started
Delay cgi requests made before the cgid daemon has started
Delay cgi requests made before the cgid daemon has started
Delay cgi requests made before the cgid daemon has started

Description Edward Lu 2015-03-10 19:36:12 UTC
Created attachment 32555 [details]
Delay cgi requests made before the cgid daemon has started

There is a short interval where httpd has started up and is accepting requests, but the cgid daemon has not yet created a listening socket. In this interval, any cgi requests made will receive a 503 response. While that response is technically correct, it seems like a retry system could be more appropriate.
Comment 1 Edward Lu 2015-03-16 15:27:43 UTC
Created attachment 32577 [details]
Delay cgi requests made before the cgid daemon has started

Rebased the patch onto trunk. Also made it not retry if the socket somehow goes away.
Comment 2 Yann Ylavic 2015-03-16 15:57:41 UTC
(In reply to Edward Lu from comment #1)
> Rebased the patch onto trunk. Also made it not retry if the socket somehow
> goes away.

You probably need to save errno after connect() and use that value in late checks.
Comment 3 Edward Lu 2015-03-16 17:22:49 UTC
Created attachment 32578 [details]
Delay cgi requests made before the cgid daemon has started

Good point. The errno currently isn't being saved in trunk, but it's being used only in the log; I guess since we're using it for more in this patch, it's better to be safe.
Comment 4 Yann Ylavic 2015-03-16 17:44:53 UTC
Maybe declare connect_errno = 0 in the loop block so that it is initialized when connect() succeeds?
Comment 5 Edward Lu 2015-03-16 18:07:02 UTC
Created attachment 32579 [details]
Delay cgi requests made before the cgid daemon has started

Done.
Comment 6 Edward Lu 2015-03-16 18:14:16 UTC
Created attachment 32580 [details]
Delay cgi requests made before the cgid daemon has started

Forgot to take out a call to sleep I was using while testing. Sorry about all the revision spam.
Comment 7 Eric Covener 2015-03-17 20:14:09 UTC
Thanks Ed and Yann, committed with minor tweaks in r1667385
Comment 8 Brad Newman 2015-05-19 17:51:08 UTC
I encountered this problem with httpd 2.4.9, and tried the patch.  

Unfortunately, the 503 responses with the same "(2)No such file or directory: AH01257: unable to connect to cgi daemon after multiple tries" error also happen after a *graceful* restart of httpd.  

But the graceful restarts don't reset the scoreboard's restart_time, so if httpd has been running for more than a minute when the graceful restart occurs, we end up in the APLOGNO(02831) branch and don't benefit from any retries.
Comment 9 Christophe JAILLET 2017-05-25 12:22:16 UTC
This has been merged in 2.4.x in r1669559.

Is is part of 2.4.13