ENOMEM and tcp sockets?

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
larsks
Posts: 22
Joined: Mon Feb 13, 2017 5:27 pm

ENOMEM and tcp sockets?

Post by larsks » Wed Nov 08, 2017 6:59 pm

I am running Micropython 1.9.3 (v1.9.3-8-g63826ac5c) on an esp8266 device.

Does micropython raise ENOMEM for reasons other than actually running out of memory? I'm trying to write a simple http server; you can see the code at https://gist.github.com/larsks/1cf5f8cd ... b93433cc32. It doesn't do anything right now other than parse an HTTP request and send a short one-line response.

I am consistently getting:

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "server.py", line 107, in <module>
  File "server.py", line 78, in serve
  File "server.py", line 74, in create_socket
OSError: [Errno 12] ENOMEM
Where line 74 is:

Code: Select all

        s.listen(1)
Am I doing something wrong here? Am I *actually* running out of memory? How can I check? After the ENOMEM exception, gc.mem_free() reports:

Code: Select all

>>> gc.mem_free()
24400
And esp.freemem() reports:

Code: Select all

>>> esp.freemem()
8632

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: ENOMEM and tcp sockets?

Post by Roberthh » Wed Nov 08, 2017 8:14 pm

You get that error if you have a socket open and the perform a warm boot (Ctrl_D) or try otherwise to re-uses these.. You have either to close the sockets or do a hard reset to release the sockets.

larsks
Posts: 22
Joined: Mon Feb 13, 2017 5:27 pm

Re: ENOMEM and tcp sockets?

Post by larsks » Wed Nov 08, 2017 9:16 pm

You get that error if you have a socket open and the perform a warm boot (Ctrl_D) or try otherwise to re-uses these.
That was it! I didn't realize that open sockets would persist over a soft reset like that.

Post Reply