question

Upvotes
Accepted
21 7 6 11

Websocket API Future finished exception code=1001, reason='Going Away'

Hi,

I am testing to receive underlying options from a chain using the WebSocketAPI with Python in Windows.

Error message:

"Future exception was never retrieved

future: <Future finished exception=ConnectionClosedOK(Close(code=1001, reason='Going Away'), Close(code=1000, reason=''), False)>

websockets.exceptions.ConnectionClosedOK: sent 1000 (OK); then received 1001 (going away) Going Away"

It fails each time on loop 977.


Any advise on the meaning of this error and a possible resolution is appreciated. Simple code enclosed below (removed connection details):

import asyncio
import json
import socket
import websockets

hostname = ''
port = ''
ws_address = "ws://{}:{}/WebSocket".format(hostname, port)
user = ''
app_id = ''
position = socket.gethostbyname(socket.gethostname())

login_json = {
    'ID': 1,
    'Domain': 'Login',
    'Key': {
        'Name': '',
        'Elements': {
            'ApplicationId': '',
            'Position': ''        }
    }
}
login_json['Key']['Name'] = user
login_json['Key']['Elements']['ApplicationId'] = app_id
login_json['Key']['Elements']['Position'] = position

async def hello(initial_name):
    store = []
    #websocket vs websockets
    async with websocket.connect(ws_address, extra_headers={'User-Agent': 'Python'},
                                  subprotocols=['tr_json2'], ping_timeout=None, ping_interval=5) as websocket:
        await websocket.send(json.dumps(login_json))
        await websocket.recv()
        async def get_data_for_name(message):
            await websocket.send(json.dumps({
                'ID': 2,
                'Key': {
                    'Name': message,
                    'Service': '$svc',
                },
                "Streaming": False            }))
            res = await websocket.recv()
            json_res = json.loads(res[1:-1])
            store.append(json_res)
            print(json_res)
            if len(json_res['Fields']['BR_NEXTLR']) > 0:
                await get_data_for_name(json_res['Fields']['BR_NEXTLR'])
        await get_data_for_name(initial_name)
asyncio.run(hello('0#$chain'))


Kind regards,

Johan

trep#productwebsockets
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

<AHS>

Just FYI. There is an old case 11653219 with a similar error message:

  • Case: Case 11653219: Websocket API, "ERROR:websocket:close status: 1001" when websocket closed
  • Problem: Websocket API application got ERROR:websocket:close status: 1001 when it connects to TREP 3.6
  • Root Cause: The application called logging.info(..) and RTDS 3.6 which improve websocket.
  • [Solution] Use print(..) method instead. Unfortunately, the client cannot accept this solution. They will let the error is shown.

Note: I do not have time to check yet.

Hi @johan.lundquist ,


Thank you for your participation in the forum.

Is the reply below satisfactory in resolving your query?

If yes please click the 'Accept' text next to the most appropriate reply. This will guide all community members who have a similar question.

Otherwise please post again offering further insight into your question.

Thanks,

AHS

Hi,

Please be informed that a reply has been verified as correct in answering the question, and marked as such.

Thanks,

AHS

Upvotes
Accepted
78.8k 250 52 74

@johan.lundquist

Thanks for reaching out to us.

The Refinitiv Real-Time WebSocket has its own ping/pong mechanism. The application will receive a ping message and it needs to send a pong message back to the server.

Recieved:
{
        "Type": "Ping"
}
Sent:
{
    "Type": "Pong"
}

Therefore, you need to remove the ping_timeout and ping_interval settings from the WebSocket connection.

    async with websockets.connect(ws_address, extra_headers={'User-Agent': 'Python'},
                                  subprotocols=['tr_json2']) as websocket:

I am unable to replicate the error. Please share the chain RICs that you are using.

I hope that this information is of help.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
21 7 6 11

Thank you @Jirapongse,

It didn't help instead I got:

"websockets.exceptions.ConnectionClosedError: sent 1011 (unexpected error) keepalive ping timeout; no close frame received"

Adding back ping_timeout=None and I get the other error:

future: <Future finished exception=ConnectionClosedOK(Close(code=1001, reason='Going Away'), Close(code=1000, reason=''), False)>

websockets.exceptions.ConnectionClosedOK: sent 1000 (OK); then received 1001 (going away) Going Away.

I guess this would be the same for any Chain RIC with more than 977 BR_NEXTLR? In my specific case it is actually towards Bloomberg's 0#bgBBG000H4FSM0 via Bloomberg MFA pipe to TREP.

Kind regards,

Johan

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

@johan.lundquist

As I know, the Refinitiv Real-Time WebSocket has its own ping/pong mechanism. It doesn't rely on the ping mechanism in the WebSocket.

If I set "ping_interval=5" in the WebSocket, I get an error because the server doesn't recognize the WebSocket internal ping messages.

However, you may need to contact the server team to verify its settings and the reason for the disconnection.


Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.