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

mapserv.exe doesn't flush file buffers during process termination #4505

Closed
szekerest opened this issue Oct 21, 2012 · 8 comments
Closed

mapserv.exe doesn't flush file buffers during process termination #4505

szekerest opened this issue Oct 21, 2012 · 8 comments
Assignees
Milestone

Comments

@szekerest
Copy link
Member

We have experienced strange behaviour of the WMS GetCapabilities response of MapServer CGI on Windows 2008 and Windows 7 which is truncated. The same thing happens when invoking mapserv from the command line and the output is redirected to a file.

After a bit of investigation, I came to the conclusion that the process termination doesn't necessarily flush the file buffers (incl. stdout and stderr) on Win 2008 and Win 7. This is primarily an OS behaviour which works correctly on Win2003/XP, but it should probably be fixed in MapServer by calling fflush(NULL) at the right place.

@ghost ghost assigned szekerest Oct 21, 2012
szekerest added a commit to szekerest/mapserver that referenced this issue Oct 21, 2012
@jmckenna
Copy link
Member

This issue keeps popping up, but is difficult to duplicate. Thanks for this fix, I'll keep my eyes open for new mentions of this issue.

@dmorissette
Copy link
Contributor

Are you sure that in the cases you tested the process does not crash or abort somehow? I mean, having to explicitly call fflush() at the end of execution for every command-line C program seems like a huge flaw in the OS, and I would tend to question our own code first (maybe even a bug related to the way the msIO_* stuff is implemented?)

Before going ahead with the patch, could someone perhaps try running the following test program to confirm that it is indeed an OS problem, and not a side-effect of a bug in the MapServer code?

#include <stdio.h>

int main()
{
  int len = 0;

  while (len < 4200) {
    len += printf("(%d) This is a test.\n", len);
  }

  /* If output is aborted, then uncomment the fflush() call */
  /* fflush(stdout) */

}

If the output stops before outputting a line numbered above 4096 then it is indeed a huge Windows flaw related to buffering, otherwise if the test program outputs values above 4096 then it would be a bug elsewhere in MapServer. Here is what I get on Linux for reference (i.e. output not truncated):

...
(4042) This is a test.
(4065) This is a test.
(4088) This is a test.
(4111) This is a test.
(4134) This is a test.
(4157) This is a test.
(4180) This is a test.

@tbonfort
Copy link
Member

since no one seems interested to investigate this issue more deeply, can we just apply this fix which only concerns our windows packagers, and move on with the release process please ?

@dmorissette
Copy link
Contributor

I'm only +0 as I usually like to understand the root of a problem before calling it fixed... but Windows ain't my territory and nobody's going to be injured by an extra fflush() on process termination.

@jmckenna
Copy link
Member

This issue is extremely difficult to duplicate. I vote +1 for committing as-as, and I'll keep my eyes open for reports of this again.

@szekerest
Copy link
Member Author

I cannot reproduce the issue by using the test application provided above. It may however be a mapserver issue with some kind of abnormal termination.

@szekerest
Copy link
Member Author

Added flush(stdout) to mapserv.exe on Windows. It is indeed a buffering problem (disabling the buffering with setvbuf(stdout, NULL, _IONBF, 0) could also solve the issue), but it is difficult to explain whether this is a bug in mapserver or a feature in the OS.

@raymondnijssen
Copy link

Today I ran into this on a Linux Server. My GetCapabilities response is truncated at 4096 bytes. GetMap works fine though.

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

5 participants