Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Winsock "not enough memory to complete this operation" error

Status
Not open for further replies.

mibosoft

Programmer
Jul 23, 2002
106
SE
Hi,
I would be grateful if someone could give me a hint on the following problem:

Since several years, I'm running a web application based on a Winsock server written by Markus Voellmy:

It uses a "pseudo multi threading" by creating a new object for each incoming connection request. My application parses incoming GET and POST requests via winsocks datarrival() event and is using the senddata() function to return HTML code, images, scripts, etc, to the clients browser.

Sometimes, escpecially when you haven't used the application for a while and open a new web browser and request a web page (with HTTP GET) from my application that has quite a lot of HTML in it, I get "Not enough memory to complete this operation". The whole application hangs and crashes with "Unhandled Exception: Access Violation (C00005)".

To track the error, I write to a log file and the error seems to happen just before the senddata() call. I have a SYS(1016) here ("Returns amount of memory being used by objects you define") and it reports 2033612 which I assume is in bytes.

I have have read somewhere that senddata() can be flooded and tried to put an inkey(.1) both after and before the sendata() but it still crashes.

I run about 20 instances of my application (one per customer) using different ports, on the same Windowss 2008 RC2 server. msvcr71.dll and the VFP dll's vfp9r.dll etc are shared by all instances.

The crashes started to happen this autumn. My application grows, i.e. I add new functionality every now and then but nothing major. The winsock class that handles everything is about 9000 lines of code and has a big "do case" command in it that parses the incoming GET and POST requests.

Any idea how I can avoid this frustrating problem?

Thanks,
Micael
 
I would have an idea, that would help for situations with many concurrent users. That would simply be to compile as MTDLL (multi threaded) using the vfp9t.dll runtime instead of vfp9r.dll

This runtime is non reentrant and the help on DLL vs MTDLL is explaining what happens, in one of the cases each session works on it's own auto created copy of the vfp runtime dll(s).

But since this happens when the server "wakes up" on the first call, that's obviously not the problem.

Yes, sys(1016) reports memory usage in bytes, but only usage by objects and variables. 2033612 is not a large number, here. But you define what the process allocates at max via SYS(3050), and if you set this low because you fear many such parallel processes will each need heir 2MB, then this can be a hurdle leading to the memory error. This memory is not allocated from the start and VFP does not allocate more than you specify here. VFP does not automatically extend that memory, certain operations like rushmore simply fail with such an error, if that setting is not large enough, even though there would be plenty of RAM or swap file could be used for he rescue. Setting it to 2GB is also no solution, but see, if you find an initialisation in your code setting SYS(3050). It looks like you fail on 2MB, because there is such a limit seet somewhere in your init.

Bye, Olaf.

 
Winsock is notorious for memory leaks. For some of my applications using it, I have had to periodically reduce working memory using the following API routines:

Code:
Declare Integer SetProcessWorkingSetSize In kernel32 As SetProcessWorkingSetSize  ;
   Integer hProcess , ;
   Integer dwMinimumWorkingSetSize , ;
   Integer dwMaximumWorkingSetSize

Declare Integer GetCurrentProcess In kernel32 As GetCurrentProcess

nProc = GetCurrentProcess()
=SetProcessWorkingSetSize(nProc,-1,-1)


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Thank you for your answers. Good hints! However, I might have solved the problem today after several hours of troubleshooting.

I use "textmerge to memvar" to prepare the HTML output buffer and the data is picked from memo fields. Dynamic data is brought in via <<command>> and sometimes this includes function calls. One of the called functions used & (macro substitution) to pick data from another memo field and sometimes, apparently when winsock had a lot to do, the error "function name is missing.)" was thrown. This caused a memory bloat and VFP crashed with an exception.

I have used this code for a long time so I don't understand why it haven't triggered before. Anyway, I removed the macro substitution and the crashes seems to be gone :)

Thanks'
Micael Borgefeldt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top