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
  How to timeout a task using the ThreadpoolExecutor? lowercase00 2 5,079 Feb-07-2023, 05:44 PM
Last Post: deanhystad
  TimeOut a function in a class ? Armandito 1 2,450 Apr-25-2022, 04:51 PM
Last Post: Gribouillis
  FTp timeout except korenron 2 5,269 Feb-01-2022, 06:51 AM
Last Post: korenron
  Class Method to Calculate Age Doesn't Work gdbengo 1 2,472 Oct-30-2021, 11:20 PM
Last Post: Yoriz
  printing contents of Jar on timeout Rakshan 1 2,260 Jul-30-2021, 07:48 AM
Last Post: buran
  UART Serial Read & Write to MP3 Player Doesn't Work bill_z 15 8,777 Jul-17-2021, 04:19 PM
Last Post: bill_z
  Read a single event (keypress) from asyncio cygnus_X1 3 6,739 May-26-2021, 07:43 PM
Last Post: deanhystad
  TypeError: type str doesn't define __round__ method emmapaw24 7 37,246 Feb-03-2020, 08:38 PM
Last Post: snippsat
  why my method doesn't find my List in the same class? Scorpio 2 2,925 Jan-31-2019, 05:21 PM
Last Post: Scorpio
  socket.timeout: timed out DanielGraham 2 22,067 Dec-22-2017, 06:07 PM
Last Post: DanielGraham

Forum Jump:

User Panel Messages

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