Websocket signature_subscribe times out

Using SolanaPy, signature_subscribe randomly times out without any returned error.

async with connect(wss_url) as websocket:
    await websocket.signature_subscribe(signature, "confirmed")

    logger.info("Listening for confirmed status") <-- Randomly times out before this log

    first_resp = await websocket.recv()
    subscription_id = first_resp[0].result
    next_resp = await websocket.recv()
    await websocket.signature_unsubscribe(subscription_id)
    return next_resp

This works about 85% of the time, however randomly it fails with a time out. I set some logs to determine where the function was failing and came to the conclusion that signature subscribe randomly does not complete. What can be the cause of this and what would be the best way to resolve this type of issue?

I was thinking maybe a while loop within a set time period but I felt that was a hack approach. Maybe there is a better way?

Related Articles