开发者

StackOverflow when hosted as WCF - works fine in Console app

I have an app that uses EF. 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)开发者_JS百科.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜