Python Forum
Asyncio StreamReader read method doesn't respect timeout when using SSL
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Asyncio StreamReader read method doesn't respect timeout when using SSL
#1
I'm making requests to SSL servers using asyncio's streams.
Here is an example method.

async def make_request():
    async with asyncio.connect('127.0.0.1', 8888, ssl=ssl.SSLContext()) as stream:
        await stream.write(REQUEST)
        print(await stream.read(RESPONSE_LENGTH))
Some of the server complete the SSl handshake, receive the request but don't send any response. This makes the method stuck on the stream.read call as expected.

In such cases I want to define a timeout for the read call. I have tried to achieve this by adding a wait_for.
print(await asyncio.wait_for(stream.read(RESPONSE_LENGTH),timeout=2))
However, this method doesn't work and continues to block indefinitely.
Additionally, if we use a plain TCP connection the fix I proposed works fine.

Whats wrong with my solution? Is there an alternative way to achieve it?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  FTp timeout except korenron 2 3,574 Feb-01-2022, 06:51 AM
Last Post: korenron
  Class Method to Calculate Age Doesn't Work gdbengo 1 1,700 Oct-30-2021, 11:20 PM
Last Post: Yoriz
  UART Serial Read & Write to MP3 Player Doesn't Work bill_z 15 5,796 Jul-17-2021, 04:19 PM
Last Post: bill_z
  Read a single event (keypress) from asyncio cygnus_X1 3 4,298 May-26-2021, 07:43 PM
Last Post: deanhystad
  TypeError: type str doesn't define __round__ method emmapaw24 7 29,600 Feb-03-2020, 08:38 PM
Last Post: snippsat
  why my method doesn't find my List in the same class? Scorpio 2 2,378 Jan-31-2019, 05:21 PM
Last Post: Scorpio
  timeout value in subprocess jonesin1974 2 5,034 Dec-01-2017, 02:18 PM
Last Post: snippsat
  Using asyncio to read text file and load GUI QueenSvetlana 1 4,797 Nov-09-2017, 02:55 PM
Last Post: heiner55
  Pyusb freeze when using Dev.read(nr,nr,timeout=1000) bojane 3 7,511 Jan-11-2017, 10:17 AM
Last Post: bojane
  AsyncSSH and timeout Standard_user 1 5,486 Nov-03-2016, 06:05 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020