Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IIS server returns HTTP 500 errors outside of FastCGI loop #6411

Closed
geographika opened this issue Sep 17, 2021 · 10 comments
Closed

IIS server returns HTTP 500 errors outside of FastCGI loop #6411

geographika opened this issue Sep 17, 2021 · 10 comments
Assignees

Comments

@geographika
Copy link
Member

As noted in #6303 - Windows IIS (and possibly other servers) return HTTP 500 errors if the program exits, rather than returning an HTTP response with an error. This makes it hard to diagnose the underlying issue - for example the path to the config file could be incorrect, or the environment variable is missing.

Examples:

MapServer/mapserv.c

Lines 144 to 148 in 17d8fa9

if( msSetup() != MS_SUCCESS ) {
msCGIWriteError(mapserv);
msCleanup();
exit(0);
}

MapServer/mapserv.c

Lines 156 to 158 in b55b128

if(config == NULL) {
msCGIWriteError(mapserv);
exit(0);

Attempts to exit within the FCGI_Accept() >= 0 loop worked once and then failed.
Possible solution is to simply keep going to goto end_request;

@geographika geographika self-assigned this Sep 17, 2021
@sdlime
Copy link
Member

sdlime commented Sep 19, 2021

I have a feeling we'll need an alternative to msCGIWriteError() for this use case, something more independent of any initialization or setup.

@geographika
Copy link
Member Author

A couple of things that didn't work:

I think what we probably want to happen is either:

  1. The process fails, but somewhere the issue of a missing config file is logged - currently on IIS the HTTP 500 error is returned. Request logging only produces:
ModuleName FastCgiModule 
Notification EXECUTE_REQUEST_HANDLER 
HttpStatus 500 
HttpReason
HttpSubStatus 0 
ErrorCode The operation completed successfully.  (0x0) 
  1. We let the process continue (the FastCGI loop), but each request simply outputs the same MapServer error

I'm interested how this appears on other web servers - does setting MAPSERVER_CONFIG_FILE to a missing file return HTTP 500 with no logs/messages?

@sdlime
Copy link
Member

sdlime commented Sep 20, 2021

I can confirm the 500 error with FastCGI using Vagrant. Nothing in the logs other than the standard "End of script before headers: mapserv.fcgi". The setup is:

  1. No config file defined as an environment variable using SetEnv or FcgiidInitialEnv.
  2. Using "wget -0 - http://localhost/cgi-bin/mapserv.cgi" or mapserv.fcgi.

The CGI returns the config file not found error as expected.

@sdlime
Copy link
Member

sdlime commented Sep 21, 2021

@geographika, if I change the configuration error handling to do some FastCGI related initialization before writing the error then I don't see a 500 error and get the expected error message. @rouault, wondering if you think this is reasonable...

  config = msLoadConfig(NULL); // is the right spot to do this?                                                                           
  if(config == NULL) {
#ifdef USE_FASTCGI
    msIO_installFastCGIRedirect();
    FCGI_Accept();
#endif
    msCGIWriteError(mapserv);
    exit(0);
  }

@geographika
Copy link
Member Author

@sdlime - I can confirm with this update on IIS/FastCGI I get the following error with an invalid path, rather than a generic HTTP 500 error:

msLoadConfig(): Unable to access file. (C:\MapServer\bin\mapserver.confx)

And when missing the environ variable MAPSERVER_CONFIG_FILE (as it defaults to the default path):

msLoadConfig(): Unable to access file. (/mapserver.conf)

This will make it much easier for users to setup/diagnose the issue.

@sdlime
Copy link
Member

sdlime commented Sep 21, 2021

Thing is that I don't think we should be outputting the config file name/path.

@geographika
Copy link
Member Author

A generic msLoadConfig(): Unable to access the config file set in the MAPSERVER_CONFIG_FILE variable would be enough to start debugging whilst remaining secure?

@sdlime
Copy link
Member

sdlime commented Sep 21, 2021 via email

sdlime added a commit to sdlime/mapserver that referenced this issue Sep 21, 2021
@sdlime
Copy link
Member

sdlime commented Sep 24, 2021

@geographika, think we can close this?

@geographika
Copy link
Member Author

Yes, fixed as part of #6303 - thanks @sdlime !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants