views:

94

answers:

1

I have an app that uses EF (i've seen the 'EF has a bug and StackOverflows' posts thanks). To test my stuff I generally wrap a simple console app around my code, run, rinse repeat till I get it right... So I was pretty surprised to see a stackoverflow when I moved my code to IIS.

Right now I get this problem on IIS 7.5 (windows 7 from MSDN). I have "gigs" of memory free but the code doesn't seem to require 'that much' memory and like I said - the console app run just fine...

So I'm no IIS wizard but I'm wondering if I can manually increase the stack size or bump the memory w3wp uses etc... (it's under 200 M right now).

I can't "bing/yahoo/google" this effectively because nearly every reference to "stackoverflow" points back here !! So i figured I'd ask the community and see what y'all got... :)

Thanks in advance. If you need any followups answered post a comment and I'll try to check back every 30 minutes (or so)

+2  A: 

A stack overflow occurs when your stack size reaches the defined limit and no more elements can be placed on the stack. The default stack size in Windows is normally 1 MB and has nothing to do with the total memory available to a process (therefore looking at the memory used by w3wp.exe makes not much sense in your case).

It is possible to increase the stack size of an executable. From a Visual Studio command prompt you can issue

editbin /STACK:4000000 w3wp.exe

to increase the stack size to 4 MB.

However, it could also be the case that the stack overflow is caused by a problem in the code (typically an infinite recursion) which would only occur when hosted as a WCF service.

To trace this problem down, you need to find out where the recursion occurs. If you can't get a stack trace intensive logging will help you here.

UPDATE

As it seems, w3wp.exe does not use Window's default stack size of 1 MB but uses only 256 kB (see also this knowledge base article):

dumpbin /HEADERS c:\windows\system32\inetsrv\w3wp.exe

prints:

[...]
OPTIONAL HEADER VALUES
[...]
    40000 size of stack reserve

A blog post suggest to patch w3wp.exe using editbin as described above.

0xA3
it's not infinite recursion related. as i state in the original question - it runs FINE in the context of a console application but once hosted as WCF it dies with the stackoverflow exception.what i am looking for are things like what you touched on "the default stack size in windows is normally 1 MB". That's fine - but is the stack size DIFFERENT when hosted under iis 7.5? (or 6 or 7 for that matter)
dovholuk
I feel for ya brotha. My code runs fine when I run it in a console app, but when I copy/paste it into an entirely different application it also breaks. I have no idea why that could be, as it works in the console app. Threading's for losers, so I don't worry about code that works in a single threaded app breaking in a multithreaded one. And I'm a REAL coder, so I won't ever use unit tests to ensure my code executes as expected in the actual application that its supposed to run in.
Will
thanks for the pointer... this is what i'm talking about... the next issue i have to tackle is windows file protection not letting me touch w3wp.exe...
dovholuk
Not only file protection might be an issue, but w3wp.exe might be updated by hotfixes and service packs. You'd be safer with redesigning your code to use less stack space as "256kB ought to be enough for everyone" ;-).
0xA3
totally agree - already moving to do so... thanks for the comments and help.
dovholuk