Skip to content

Picoweb is eating memory: How to debug? #66

@ctschach

Description

@ctschach

Hi,

I'm using the git version of picoweb running on an ESP32. Everything works smoothly. I do have a second ESP32 which posts data every 6 minutes to the "server". Everything looks good.

However, over time the "server" is showing less and less memory available. I've printed some debug messages with gc.mem_free().

This comes to a point where the server is not responding anymore. If you use telnet to connect to port 80 of the ESP "server" the connection is closed instantly again. No debug messages, no error messages.

There are still around 27000 bytes left of memory, so it's not that low.

I do have other functions running with uasyncio.create_task. The interesting fact is, that the server is not eating any memory if here is no web-interaction. If it just run the internal routines everything is fine and runs forever, but as soon as I start frequent server communication things are getting worse.

The function that is called frequently by the server is this:

def web_batteryslave(req, resp):
    gc.collect()
    print('%%% Web Start: Free Memory: ', gc.mem_free())
    method = req.method

    if req.method == "POST":
        size = int(req.headers[b"Content-Length"])
        data = yield from req.reader.read(size)
        #print('$$$ Data:    ', data)
        try:
                decoded = ujson.loads(str(data)[2:-1])
                yield from picoweb.start_response(resp)
                yield from resp.awrite("OK")
                yield from resp.awrite("\r\n")
                thisId = decoded['id'];
                # Save data from this sensor to measurements
                toolbox.measurements[thisId] = decoded
                print('%%% WEB End: Free Memory: ', gc.mem_free())
                return
        except:
                yield from picoweb.start_response(resp)
                yield from resp.awrite("NOK")
                yield from resp.awrite("\r\n")

The data in 'toolbox.measurements' is "just" updated every time, there is no new data added. The same functionality with storing the data works fine with local sensors without an memory leaks.

I've see other issues here and the discussion if the connection needs to be closed or not.

So how can this be debugged?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions