Closed
Description
While testing the WebSocketTransport
to run subscriptions I've started to get random errors. Turns out it was keep-alive ping that server ignored:
DEBUG:websockets.client:% sending keepalive ping
DEBUG:websockets.client:> PING 15 b4 8b 07 [binary, 4 bytes]
DEBUG:websockets.client:! failing connection with code 1006
DEBUG:websockets.client:= connection is CLOSED
Fix
My initial thought was to set ping_interval=None
and that would stop connection from dropping (passing it through to websockets
args). However, this changed nothing. And after a little bit of investigation I tried to pass connect_args={"ping_interval": None}
to influence websockets
directly and it worked like a charm.
Expected behavior
I believe ping_interval=None
should change websockets ping_interval
argument. If I'm wrong than this could be stated somewhere in the docs or an argument's docstring. Thanks in advance!
To reproduce
You may query this graph.
from gql import gql, client
from gql.transport.websocket import WebsocketTransport
import asyncio
import logging
TARGET_GRAPH = "wss://api.thegraph.com/subgraphs/name/uniswap/uniswap-v3"
logging.basicConfig(level=logging.DEBUG)
WS = WebsocketsTransport(
TARGET_GRAPH,
ping_interval=None,
)
CLIENT = Client(transport=WS, fetch_schema_from_transport=False)
TESTQ = gql("""
subscription test {
pool(id: "0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8") {
token0 { symbol decimals }
token1 { symbol decimals }
feeTier
sqrtPrice
liquidity
}
}
""")
if __name__ == "__main__":
async def foo():
async with client as session:
async for result in session.subscribe(FACTORY_Q): # type: ignore
print(result)
asyncio.run(foo())