Re: net.createConnection Function always takes memory
Posted: Sun Apr 02, 2017 9:31 am
limbo wrote:I know this is a known issue.
Where did you pick that up? It's neither a known issue nor were you quoting an actual example from our documentation IIRC. The closest we have is with http://nodemcu.readthedocs.io/en/latest ... etsocketon
Code: Select all
srv = net.createConnection(net.TCP, 0)
srv:on("receive", function(sck, c) print(c) end)
srv:on("connection", function(sck, c)
-- Wait for connection before sending.
sck:send("GET /get HTTP/1.1\r\nHost: httpbin.org\r\nConnection: keep-alive\r\nAccept: */*\r\n\r\n")
end)
srv:connect(80,"httpbin.org")
If you access the `srv` variable within a `srv.on` callback function (as with your example) you're actually creating a memory leak. Some explanation is here: http://stackoverflow.com/a/37379426/131929.
What you're likely seeing (besides the above) is too many open sockets in TIME_WAIT status i.e. not yet closed. https://github.com/nodemcu/nodemcu-firmware/pull/1838 reduced the number of seconds such sockets should be kept around. You might also try to replace `Connection: keep-alive` with `Connection: close` and see how the server reacts.