West Wind Internet and Client Tools
wwHttp - Insufficient stack space error with larger json
Gravatar is a globally recognized avatar based on your email address. wwHttp - Insufficient stack space error with larger json
  Ondrej Vojtechovský
  All
  Feb 15, 2022 @ 12:53am

Hello Rick,

I am successfully using wwHttp for making REST API requests. But this time, I need to send quite large data. JSON file is around 1 MB. And I am getting "insufficient stack space" error on loHttp.Post().

lcUrl = "https://externalservicesmanagement-test.alza.cz/dropship-validator/v1/availability?token=8gZMZdw9Rrq%2BRGK2bxKYUS5eHRs%3D"

lcJson = Filetostr(....)

Do wwhttp
loHttp = CREATEOBJECT("wwHttp")
loHttp.cContentType = "application/json"
loHTTP.nConnectTimeOut = 30
loHTTP.cHttpVerb = "POST"
loHttp.AddPostKey(lcJson)
lcResult = loHttp.Post(m.lcUrl, lcJson)

Sample JSON file

Is there anything I can do to make it work?

Thank you.

Best regards,
Ondrej

Gravatar is a globally recognized avatar based on your email address. re: wwHttp - Insufficient stack space error with larger json
  Rick Strahl
  Ondrej Vojtechovský
  Feb 15, 2022 @ 11:08am

What exactly is the error and where exactly is it failing? Are you getting a FoxPro exception, a C5 or is this a message from the server?

A 1mb download should be no problem in an application unless you are extremely memory constrained on your machine or FoxPro is already using a ton of memory.

Also just noticing: You're doing both AddPostKey() and then adding the data via the Json parameter - only do one or other (the Post() method is the right place for raw content).

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: wwHttp - Insufficient stack space error with larger json
  Ondrej Vojtechovský
  Ondrej Vojtechovský
  Feb 18, 2022 @ 02:18am

Hi,

I am testing it in simple prg. It is not part of any application so far. I just start Visual FoxPro, set enviroment (paths, variables like date format, century, ...) and run testing prg containing code written in original question.

Here is what i get when it reaches loHttp.Post():

I tried to send same request using .NET HttpClient and there is no problem. So I am able to use wwDotNetBridge with .NET class instead of wwHttp. For me, wwHttp works only for smaller JSONs.

Gravatar is a globally recognized avatar based on your email address. re: wwHttp - Insufficient stack space error with larger json
  Rick Strahl
  Ondrej Vojtechovský
  Feb 18, 2022 @ 12:19pm

Not sure... as I said works for me (and many others - never heard about this happening) but I then again I have a ton of memory.

Insufficient Stackspace occurs either when FoxPro is out of memory or if you end up in some sort of recursive loop (which actually produces a different Stack Overflow) error.

Could it be that the response is really large?

If you have source code (ie a registered version) you can step through the code and see where it actually blows up in the send operation. That might shed some more light but I can't see why it would blow up other than some resource issue.

Maybe your FoxPro memory settings are really low...

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: wwHttp - Insufficient stack space error with larger json
  Juliano Terterola
  Ondrej Vojtechovský
  Nov 22, 2024 @ 08:43am

Hi there!

Maybe my comment may help someone looking for help in the future... I just got the same message here in another context (Insufficient stack space) without using wwHttp. In more than 30 years working with VFP, I've never seen this error before.

Although the message looks like a problem with a lack of physical memory, looking at the process consumption at the time of the error, it was normal and very low.

In my case, I realized that the error was due to me saving an extremely large string in the _CLIPTEXT variable. Later, when my code needed to use _CLIPTEXT again, the error occurred.

My solution was just not to save the string in _CLIPTEXT, as it was just for debuging purpose.

So, it's possible that the problem for other people is related to something like this too, a very (very!) long string (over 500,000 characters) being assigned to a variable and then trying to reuse it.

Hope this helps.

Regards,

Gravatar is a globally recognized avatar based on your email address. re: wwHttp - Insufficient stack space error with larger json
  Rick Strahl
  Juliano Terterola
  Nov 22, 2024 @ 12:35pm

Stackspace typically refers to FoxPro's working stack (ie. in method memory allocation which is non-heap data). This amount is fairly limited, but FoxPro's memory manager will elevate to heap memory internally when allocating large strings. However, if something is taking up a lot of stack space already when the method is entered the space might so restrained it never gets to the elevation level.

This becomes a problem if code is deeply nested or you're running a recursive loop as the top level stack memory is not released.

It sounds very odd either way. The thing to do is test in a clean environment. Start FoxPro and don't load up anything (CLEAR ALL; CLOSE ALL; RELEASE ALL;) then try running the code and see if it fails the same way - it shouldn't.

+++ Rick ---

© 1996-2024