Stalls on webserver example on esp32 and esp8266


#1

Hi ,

I tested the webserver example and came to the conclusuion that it stalls the controller (either esp32 and esp8266). It happens after some variable time ranging from minutes to sometimes hours.
This is my example :

(defun println (x s) (princ x s) (princ #\return s) (princ #\newline s))


(defun webpage ()
		(pinmode 2 1)		
		(delay 10000)
		(wifi-connect "Attera Totus Sanctus" "Msp430fr5994")
		(wifi-server)

  (loop
   (with-client (s)
     (loop
      (let ((line (read-line s)))
        (when (null line) (return))
        (print line)))
    (println "HTTP/1.1 200 OK" s)
    (println "Content-Type: text/html" s)
    (println "Connection: close" s)
    (println "Refresh: 3" s) 	
    (println "" s)
    (println "<!DOCTYPE HTML><html><body><h1>ADC Value: " s)
    (princ (digitalread 2) s)
    (println "</h1></body></html>" s)
    (println "" s))
    (delay 5000)
    (digitalwrite 2 (not (digitalread 2)))))

This is the output on the serial port before it stops working :

"Host: 78.22.57.151
" 
"User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:63.0) Gecko/20100101 Firefox/63.0
" 
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
" 
"Accept-Language: en-US,en;q=0.5
" 
"Accept-Encoding: gzip, deflate
" 
"Connection: keep-alive
" 
"Upgrade-Insecure-Requests: 1
" 
"Cache-Control: max-age=0
" 
"
" 
"GET / HTTP/1.1
" 
"Host: 78.22.57.151
" 
Error: No room
2877> 

I’ve tried lots of things , but keep ending with this.
Do other people have the same issues , or is it me doing something wrong ??

Kind regards ,
Ronny Suy


#2

I’m not sure what can be causing you to run out of room here; I tried running your code on an ESP32, and inserted:

(gc)
(print (room))

inside the loop, just before the (delay 5000), to monitor the amount of free space. For me it remains constant (at 3934 free objects).

Do you have any other functions running at the same time?


#3

Hi David|

This is a snipplet of messages I get :|

Space: 21 bytes, Time: 641 us

2861 Space: 21 bytes, Time: 643 us

2861 Space: 21 bytes, Time: 643 us

2861 Space: 21 bytes, Time: 643 us

2861 Space: 21 bytes, Time: 640 us

2861 gzip, deflate
"
"Connection: keep-alive
"
"Upgrade-Insecure-Requests: 1
"
"Cache-Control: max-age=0
"
"
" Space: 419 bytes, Time: 653 us

2861 Space: 21 bytes, Time: 643 us

2861
"GET / HTTP/1.1
"
"Host: 78.22.57.151
"
"User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:63.0) 
Gecko/20100101 Firefox/63.0
"
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
"
"Accept-Language: en-US,en;q=0.5
"
"Accept-Encoding: gzip, deflate
"
"Connection: keep-alive
"
"Upgrade-Insecure-Requests: 1
"
"Cache-Control: max-age=0
"
"
" Space: 419 bytes, Time: 650 us

2861 Space: 21 bytes, Time: 643 us

2861
"GET / HTTP/1.1
"
"Host: 78.22.57.151
"
"User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:63.0) 
Gecko/20100101 Firefox/63.0
"
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
"
"Accept-Language: en-US,en;q=0.5
"
"Accept-Encoding: gzip, deflate
"
"Connection: keep-alive
"
"Upgrade-Insecure-Requests: 1
"
"Cache-Control: max-age=0
"
"
" Space: 419 bytes, Time: 671 us

2861 Space: 21 bytes, Time: 643 us

2861
"GET / HTTP/1.1
"
"Host: 78.22.57.151
"
"User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:63.0) 
Gecko/20100101 Firefox/63.0
"
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
"
"Accept-Language: en-US,en;q=0.5
"
"Accept-Encoding: gzip, deflate
"
"Connection: keep-alive
"
"Upgrade-Insecure-Requests: 1
"
"Cache-Control: max-age=0
"
"
" Space: 419 bytes, Time: 683 us

2861 Space: 21 bytes, Time: 643 us

2861
"GET / HTTP/1.1
"
"Host: 78.22.57.151
"
"User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:63.0) 
Gecko/20100101 Firefox/63.0
"
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
"
"Accept-Language: en-US,en;q=0.5
"
"Accept-Encoding: gzip, deflate
"
"Connection: keep-alive
"
"Upgrade-Insecure-Requests: 1
"
"Cache-Control: max-age=0
"
"
" Space: 419 bytes, Time: 669 us

So most of the time space: 21 , and sometimes space: 419 apparently
just when refreshing the webpage|

The code I sent is the only thing running. (I didn’t know multiple
things could be running on ulisp)|

This ‘no room’ error does it come from ulisp or from the wifi module ?

I will test further with the gc and room commands to see what happens

Kind regards ,

Ronny


#4

In your messages the figure 2861 is the amount of free space, returned by (room), which remains constant.

The “Space: 21 bytes” and “Space: 419 bytes” is the amount of garbage recovered by (gc).

The Error: No room message is printed by uLisp when it attempts to allocate an object and there’s no free space remaining. I can’t think how that could happen here, but look forward to your further tests.


#5

David,
just a fast suggestion:
Can this be caused by local variables?
Eval just calls gc if no more than 20 lispcells are available, myalloc does not call gc. If local variables need more space, could this lead to the “No room” message?

Regards,
Kaef


#6

Hi David

Last evening , night and morning it kept running without any problem , pc stayed on with firefox explorer to do a refresh every 3 seconds.

No problem , room stayed at 2861 al the time

This morning I removed (gc) and did only a print (room)

Then I see that the room is going dosn and down , sometimes to 19 cells , and going back to the initial level , see below.

Could this be the source of the problem.

Maybe sometimes the room goes to zero ? I’m going to check this now , I will keep you posted

Regards , Ronny

Here’s a snipplet of messages :

"

  "Host: 78.22.57.151

  "

  "User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:63.0) Gecko/20100101 Firefox/63.0

  "

  "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

  "

  "Accept-Language: en-US,en;q=0.5

  "

  "Accept-Encoding: gzip, deflate

  "

  "Connection: keep-alive

  "

  "Upgrade-Insecure-Requests: 1

  "

  "Cache-Control: max-age=0

  "

  "

  "

  2199

  2180

  "GET / HTTP/1.1

  "

  "Host: 78.22.57.151

  "

  "User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:63.0) Gecko/20100101 Firefox/63.0

  "

  "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

  "

  "Accept-Language: en-US,en;q=0.5

  "

  "Accept-Encoding: gzip, deflate

  "

  "Connection: keep-alive

  "

  "Upgrade-Insecure-Requests: 1

  "

  "Cache-Control: max-age=0

  "

  "

  "

  1763

  1744

  "GET / HTTP/1.1

  "

  "Host: 78.22.57.151

  "

  "User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:63.0) Gecko/20100101 Firefox/63.0

  "

  "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

  "

  "Accept-Language: en-US,en;q=0.5

  "

  "Accept-Encoding: gzip, deflate

  "

  "Connection: keep-alive

  "

  "Upgrade-Insecure-Requests: 1

  "

  "Cache-Control: max-age=0

  "

  "

  "

  1327

  1308

  "GET / HTTP/1.1

  "

  "Host: 78.22.57.151

  "

  "User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:63.0) Gecko/20100101 Firefox/63.0

  "

  "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

  "

  "Accept-Language: en-US,en;q=0.5

  "

  "Accept-Encoding: gzip, deflate

  "

  "Connection: keep-alive

  "

  "Upgrade-Insecure-Requests: 1

  "

  "Cache-Control: max-age=0

  "

  "

  "

  891

  872

  "GET / HTTP/1.1

  "

  "Host: 78.22.57.151

  "

  "User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:63.0) Gecko/20100101 Firefox/63.0

  "

  "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

  "

  "Accept-Language: en-US,en;q=0.5

  "

  "Accept-Encoding: gzip, deflate

  "

  "Connection: keep-alive

  "

  "Upgrade-Insecure-Requests: 1

  "

  "Cache-Control: max-age=0

  "

  "

  "

  455

  436

  "GET / HTTP/1.1

  "

  "Host: 78.22.57.151

  "

  "User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:63.0) Gecko/20100101 Firefox/63.0

  "

  "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

  "

  "Accept-Language: en-US,en;q=0.5

  "

  "Accept-Encoding: gzip, deflate

  "

  "Connection: keep-alive

  "

  "Upgrade-Insecure-Requests: 1

  "

  "Cache-Control: max-age=0

  "

  "

  "

  19

  2853

  "GET / HTTP/1.1

  "

  "Host: 78.22.57.151

  "

  "User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:63.0) Gecko/20100101 Firefox/63.0

  "

  "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

  "

  "Accept-Language: en-US,en;q=0.5

  "

  "Accept-Encoding: gzip, deflate

  "

  "Connection: keep-alive

  "

  "Upgrade-Insecure-Requests: 1

  "

  "Cache-Control: max-age=0

  "

  "

  "

  2436

#7

Hi David

After no more then 10 minutes I have now the No room error !

See below :

537

  518

  "GET / HTTP/1.1

  "

  "Host: 78.22.57.151

  "

  "User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:63.0) Gecko/20100101 Firefox/63.0

  "

  "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

  "

  "Accept-Language: en-US,en;q=0.5

  "

  "Accept-Encoding: gzip, deflate

  "

  "Connection: keep-alive

  "

  "Upgrade-Insecure-Requests: 1

  "

  "Cache-Control: max-age=0

  "

  "

  "

  101

  82

  "GET / HTTP/1.1

  "

  "Host: 78.22.57.151

  "

  Error: No room

  2872>

Maybe Kaef’s suggestion could be something ?

Anyway calling (gc) in the loop seems to solve the problem…

Kind regards

Ronny


#8

I had this same thought last night.

One solution would be to make the test in eval for calling gc a proportion of WORKSPACESIZE (eg 10%) rather than the fixed value 20 cells.


#9

I think the problem here is that is depends on context. On larger programs the error will be very hard to find – if even possible.
How about calling gc() from myalloc() (same way as it is called in eval())? I think this is the only place where an element of the freelist is used. If I’m right we can even move the call from eval() to myalloc().
Regards,
Kaef


#10

Unfortunately there’s a good reason for having the call to gc() in eval. Calls to myalloc() are made in many contexts where it’s not safe to do a gc().


#11

David,

I agree (and I test moving the gc call to myalloc()), so I think your solution will be a good compromise.
And I think we can assume that the complexity of programs increase if they have larger workspaces and vice versa. So your solution will remove almost all situations where the described error occurs.

Regards,
Kaef


#12

Hi David and Kaef

I took the liberty to change the c code so that in eval instead of a 20 cell threshold ,a 10% of workspacesize is used (on line 3455)

If I now run the same testprogram, without the call to (gc) , but still using (print (room)) , the result is that the roomsize stays at 2866 cells, it doesn’t even fluctuate anymore.

Can this be normal ? I’m willing to give this a night-over evaluation if you like.

Regards

Ronny


#13

That seems a bit puzzling. Can you post your new version of the line in eval:

if (Freespace < 20) gc(form, env);

#14

object *eval (object *form, object *env) {

    int TC=0;

    EVAL:

    yield(); // Needed to avoid Soft WDT Reset

    // Enough space?

    if (End != 0xA5) error(PSTR("Stack overflow"));

    if (Freespace < (WORKSPACESIZE/10)) gc(form, env);

    // Escape

    if (tstflag(ESCAPE)) { clrflag(ESCAPE); error(PSTR("Escape!"));}

    #if defined (serialmonitor)

    testescape();

    #endif

#15

Hi David ,

For your information :

The test with workspacesize/10 is still running since yesterday evening !

The reported room stays at 2866 cells.

If you want me to try other things , then please let me know.

Ronny


#16

I think you’re probably running out of space just before the (print (room)) each time around the loop, so a (gc) is triggered, and so the amount of free space printed remains constant, which is reasonable.

Good to hear that the workspacesize/10 change avoids the problem!

Can I close the topic?


#17

If it is ok for you , to use WORKSPACESIZE/10 then you may close this topic :-)

I assume there will be no side-effects for other future applications ?

One more thing : Is there a chance for the sdcard overruled by eeprom topic ?? (just asking…)

Thanks for all your effort and advice !

Ronny


#18

I can’t foresee any side-effects, but I’d like to do more testing before I make it part of the standard releases.

Also, I’m still thinking about the SDCard feature.


#19