« Previous Next »

Answered Thread: Sometimes Bad Gateway 502 by running C++ Executable on IIS

Last post 04-03-2008 6:49 PM by ma_khan. 5 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (6 items)

Sort Posts:

  • 04-03-2008, 5:40 AM

    • monoid
    • Not Ranked
    • Joined on 01-10-2008, 9:54 PM
    • Posts 4

    Sometimes Bad Gateway 502 by running C++ Executable on IIS

    Hi together,

    i have a problem by running a C++ executable on IIS. I have written a C++ script to read from stdin over post method, often it works fine. But sometimes i get a "Bad Gateway 502" - The specified CGI application misbehaved by not returning a complete set of HTTP headers.

    I write the following source code:

     int main(void)

    {

      char* szBuf = new char[length + 1];

      _setmode( _fileno( stdin ), _O_BINARY );

      fread(szBuf, sizeof(char),length,stdin);
      xs.Message = (char *) memRealloc(xs.Message,length + 1);
      strcpy(xs.Message,szBuf);

      delete [] szBuf;

    printf("Content-type:text/xml\n\n");

    return 0;

    }

     

    Does IIS need more parts for the HTTP Headers?

    Like "printf("HTTP/1.1 200 OK\n")"?

    Does anyone have a idea?

    Thanks for all!

  • 04-03-2008, 10:25 AM In reply to

    Answered Re: Sometimes Bad Gateway 502 by running C++ Executable on IIS

    Monoid,

       502 is a temp condition status code that usualy comes up when there is heavy load on the server. For more info check this http://www.w3.org/Protocols/HTTP/HTRESP.html . What is the memory consumption of w3wp when you get this error?

    Regards,
    MA Khan
    http://www.iisworkstation.com

    “Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”
  • 04-03-2008, 11:58 AM In reply to

    • anilr
    • Top 10 Contributor
    • Joined on 05-23-2006, 10:13 PM
    • Redmond, WA
    • Posts 2,343

    Answered Re: Sometimes Bad Gateway 502 by running C++ Executable on IIS

    That output should be sufficient - if you install vista sp1, the 502 error message has more information about the exact response we got from the CGI which should help further debug this problem.

    Anil Ruia
    Senior Software Design Engineer
    IIS Core Server
  • 04-03-2008, 3:45 PM In reply to

    • monoid
    • Not Ranked
    • Joined on 01-10-2008, 9:54 PM
    • Posts 4

    Re: Sometimes Bad Gateway 502 by running C++ Executable on IIS

    Hi together,

    and thank you for your answers.

    @ma_khan: The memory consumption is always 5.000 K for w3wp.exe at the Task Manager. "Bad Gateway 502" occurs sometimes, not every time and there is no consistent fault. I have tested with two similar messages and sent it via post to the C++ executable. The first message fails (RC: 502), the second works fine (RC: 200)!

    @anil_r: I have Windows 2003 Server SP 1 (multi-processor) and IIS 6.0 installed. It is not allowed to install Windows Vista on this machine.

    I have found a hotfix for IIS

    http://support.microsoft.com/kb/884764/en-us

    Does anyone have experience with this?

    Thank you for your help!

    mono

  • 04-03-2008, 4:11 PM In reply to

    • anilr
    • Top 10 Contributor
    • Joined on 05-23-2006, 10:13 PM
    • Redmond, WA
    • Posts 2,343

    Re: Sometimes Bad Gateway 502 by running C++ Executable on IIS

    Oops, sorry did not notice that this was about IIS6 and not IIS7.

    Anil Ruia
    Senior Software Design Engineer
    IIS Core Server
  • 04-03-2008, 6:49 PM In reply to

    Answered Re: Sometimes Bad Gateway 502 by running C++ Executable on IIS

    monoid:

    I have found a hotfix for IIS

    http://support.microsoft.com/kb/884764/en-us

    Does anyone have experience with this?

    Thank you for your help!

    mono

     

     Monoid,

     This KB seems to definitely point to your situation.

    "When IIS applications rely on the Common Gateway Interface (CGI) handler, errors may occur when computers with high processing rates handle multiple requests. These errors may seem random, or the errors may seem to be related, but there is no single problem source."

    I haven't come across this situation personally, but you could always try applying this fix on a dev box ... check it out for a couple of days and then move it on to prod.

    Again, Do not apply the fix on a prod server directly. FYI, this hot fix needs a reboot as mentioned in the KB ...  

    Hope this helps you...  

    Regards,
    MA Khan
    http://www.iisworkstation.com

    “Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”
Page 1 of 1 (6 items)
Microsoft Communities