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

    Socket timeout not honored with SSL

    Scheduled Pinned Locked Moved Issues & Bugs
    1 Posts 1 Posters 176 Views 1 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.
    • C Offline
      ccarreiras
      last edited by

      Has anyone faced issues with socket timeouts when using HTTPS connections?

      System information:
      sysname='GPy'
      nodename='GPy'
      release='1.18.2.r7'
      version='v1.8.6-849-df9f237 on 2019-05-14'
      machine='GPy with ESP32'

      When configuring a socket to use a timeout, if the socket has been wrapped with the ussl.wrap_socket method, the timeout is not honored.

      Given a socket sock which has been successfully connected to a host, trying to call sock.read should return None if the timeout is reached and there is nothing to read in the socket:

      import usocket
      
      sock = usocket.socket()
      sock.settimeout(5)
      
      sock.connect((host, port))
      
      t = sock.read(1)
      
      # after timeout, t is None
      print(t is None)
      

      But when the socket is wrapped with ussl, the timeout setting is ignored and read blocks forever:

      import usocket
      import ussl
      
      sock = usocket.socket()
      sock = ussl.wrap_socket(sock)
      sock.settimeout(5)
      
      sock.connect((host, port))
      
      # this hangs indefinitely
      t = sock.read(1)
      

      This also happens at least for the readline method.

      Take a look at this issue on Github:
      https://github.com/pycom/pycom-micropython-sigfox/issues/315

      1 Reply Last reply Reply Quote 1

      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