Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    OSError: [Errno -1] ERR_MEM

    Scheduled Pinned Locked Moved Firmware
    12 Posts 5 Posters 1.1k Views 5 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • robert-hhR Offline
      robert-hh @Eric Waai
      last edited by

      @eric-waai said in OSError: [Errno -1] ERR_MEM:

      ERR_MEM

      from the sources, pycom-micropython-sigfox/lib/lwip/doc/rawapi.txt

      The tcp_connect() function can return ERR_MEM if no memory is
      available for enqueueing the SYN segment. If the SYN indeed was
      enqueued successfully, the tcp_connect() function returns ERR_OK.

      and

      The tcp_write() function will fail and return ERR_MEM if the length
      of the data exceeds the current send buffer size or if the length of
      the queue of outgoing segment is larger than the upper limit defined
      in lwipopts.h. The number of bytes available in the output queue can
      be retrieved with the tcp_sndbuf() function.

      The proper way to use this function is to call the function with at
      most tcp_sndbuf() bytes of data. If the function returns ERR_MEM,
      the application should wait until some of the currently enqueued
      data has been successfully received by the other host and try again.

      and

      • err_t tcp_close(struct tcp_pcb *pcb)

      Closes the connection. The function may return ERR_MEM if no memory
      was available for closing the connection. If so, the application
      should wait and try again either by using the acknowledgment
      callback or the polling functionality. If the close succeeds, the
      function returns ERR_OK.

      T 1 Reply Last reply Reply Quote 0
      • T Offline
        timh @robert-hh
        last edited by

        @robert-hh interesting. I am getting this occasionally when using umqtt.simple to communicate with Losant with TLS. (Despite this umqtt.simple turns out to be more reliable than the underlying AWS Mqtt code).

        I am monitoring memory continuously, so it would seem , in my case it is not a system memory issue (2,500,000 bytes free - am I looking at gc.mem_free ) . It would seem this "return ERR_MEM if the length of the data exceeds the current send buffer size or if the length of the queue of outgoing segment is larger than the upper limit defined in lwipopts.h. The number of bytes available in the output queue can be retrieved with the tcp_sndbuf() function." could well be the culprit. Will investigate this further.

        Thanks for providing things.

        1 Reply Last reply Reply Quote 0
        • E Offline
          Eric Waai
          last edited by

          i also get this problem with mqtt.
          i'm getting this error quite often especially when i send nothing for a long time. but only check for mesages

          def wait_msg(self):
          		res = self.sock.read(1)
          		self.sock.setblocking(True)
          		if res is None:
          			return None
          		if res == b"":
          			raise OSError(-1)
          		if res == b"\xd0":  # PINGRESP    
          			sz = self.sock.read(1)[0]
          			assert sz == 0
          			return None
          

          i found the piece of code where the error occurs but don't know precise what is going wrong. it looks like no response from the server to me.
          it should just try again if you ask me

          H 1 Reply Last reply Reply Quote 0
          • M Offline
            Milan
            last edited by

            @Eric-Waai Yes, you are right. I've bypassed this case by removing following part of the code:

            if res == b"":
                    raise OSError(-1)
            
            E 1 Reply Last reply Reply Quote 0
            • E Offline
              Eric Waai @Milan
              last edited by

              @milan
              do you have any idea what is the reason of this problem.

              i did some testing yesterday, if i don't send anything via mqtt but do check for messages it crashes every time after 5 minutes and 16 seconds.

              T 1 Reply Last reply Reply Quote 0
              • T Offline
                timh @Eric Waai
                last edited by

                @Eric-Waai You may find that the remote connection is being closed. You may need to explicitly perform an mqtt Ping to keep the connection alive.

                E 1 Reply Last reply Reply Quote 0
                • E Offline
                  Eric Waai @timh
                  last edited by Eric Waai

                  @timh
                  thanks it looks like that is the case.
                  i added a ping every now and then and it's still going

                  i prefer this before removing errors.
                  if the error still occurs i maybe remove it but for now it stays

                  edit: still weird. i assumed that check_msg would be sufficient to keep the connection alive

                  T 1 Reply Last reply Reply Quote 0
                  • T Offline
                    timh @Eric Waai
                    last edited by

                    @Eric-Waai thats what I found, check_msg only looks to see if any data is there in the socket. I have found that a lot of MQTT services, require a ping, or some other activity to keep the session alive. Otherwise their own inactivity timeout kicks in.

                    1 Reply Last reply Reply Quote 0
                    • T Offline
                      timh
                      last edited by

                      Somewhere in my main loop i am checking connected state (which tries pinging) and causes a reconnect if it drops out. This has worked out to be robust.

                      E 1 Reply Last reply Reply Quote 0
                      • E Offline
                        Eric Waai @timh
                        last edited by

                        @timh
                        thanks for the help,

                        with pinging in between it is much more stable, it still sometimes gives the same error, i'm gonna build something similar as you have, the error at this point gives me at least an idea where it goes wrong. if i remove it some other things might go wrong

                        1 Reply Last reply Reply Quote 0
                        • H Offline
                          hibart @Eric Waai
                          last edited by

                          @Eric-Waai said in OSError: [Errno -1] ERR_MEM:

                          i also get this problem with mqtt.
                          i'm getting this error quite often especially when i send nothing for a long time. but only check for mesages

                          def wait_msg(self):
                          		res = self.sock.read(1)
                          		self.sock.setblocking(True)
                          		if res is None:
                          			return None
                          		if res == b"":
                          			raise OSError(-1)
                          		if res == b"\xd0":  # PINGRESP    
                          			sz = self.sock.read(1)[0]
                          			assert sz == 0
                          			return None
                          

                          i found the piece of code where the error occurs but don't know precise what is going wrong. it looks like no response from the server to me.
                          it should just try again if you ask me

                          Any solution to this so far?

                          1 Reply Last reply Reply Quote 0

                          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                          With your input, this post could be even better 💗

                          Register Login
                          • 1 / 1
                          • First post
                            Last post

                          Pycom on Twitter

                          Pycom