Azure / azure-relay-node

☁️Node.js library for Azure Relay Hybrid Connections
https://docs.microsoft.com/en-us/azure/service-bus-relay/relay-what-is-it
MIT License
12 stars 15 forks source link

Need to implement Listener Token Renewal in hyco-ws [Connection errors out after ~1 hour] #8

Closed SamVerschueren closed 6 years ago

SamVerschueren commented 7 years ago

Hi

I am using hyco-ws to subscribe a listener to a Relay. It works very well! But I noticed that my listener gets disconnected after 1 hour and 5 minutes. Every single time. There is nothing fancy about the error though so I can't really say where it's coming from.

{
    "type": "error",
    "target": {
        "domain": null,
        "_events": {},
        "_eventsCount": 4,
        "_socket": null,
        "_ultron": null,
        "_closeReceived": false,
        "bytesReceived": 0,
        "readyState": 3,
        "supports": {
            "binary": true
        },
        "extensions": {},
        "_binaryType": "nodebuffer",
        "_isServer": false,
        "url": "wss://foobar.servicebus.windows.net:443/$hc/path?sb-hc-action=listen",
        "protocolVersion": 13
    }
}

Does someone have any ideas as to what could cause these disconnects? Is it a timeout? Is it something else?

Thanks in advance!

dlstucki commented 7 years ago

Is the ttl on your listener's tokens one hour?

SamVerschueren commented 7 years ago

@dstuckims Thanks for the fast response! Where can I change this TTL? Can't seem to find it in the Azure Portal and it doesn't seem to be an option in the ws library either.

dlstucki commented 7 years ago

I'm not very familiar with this node project yet (it's on my todo list). @clemensv may be able to provide some help here as well but it's likely this token update may need to be added to this azure-relay-node project.

The HybridConnection websocket protocol supports a listener "gesture" (JSON command) for renewing the token. It would entail the listener sending a new token like this around the time the previous token expires:

{
  "renewToken" : {
    "token" : "SharedAccessSignature sr=http%3a%2f%2fcontoso.servicebus.windows.net%2fhybrid1%2f&sig=XXXXXXXXXX%3d&se=1471633754&skn=SasKeyName"
  }
}
SamVerschueren commented 7 years ago

So basically, after 1 hour, I will have to renew the token in order to keep the connection alive and to prevent it from being killed after 1 hour and 5 minutes?

Is this something you guys see to automatically handle inside hyco-ws?

jtaubensee commented 7 years ago

@SamVerschueren - Yes, that is correct. The library should do this today, so it is something that will have to be implemented. Technically the token should expire after an hour, but we allow for an hour and 5 minutes to account for potential clock skew.

dlstucki commented 7 years ago

@SamVerschueren, can you please indicate how you are setting the Token currently? Are you using environment variables process.env.SB_HC_KEYRULE and process.env.SB_HC_KEY or setting them like below?

    var wss = WebSocket.RelayedServer(
        {
            // create the 
            server : WebSocket.createRelayListenUri(ns, path),
            token: WebSocket.createRelayToken('http://'+ns, keyrule, key)
        });
SamVerschueren commented 7 years ago

Like the below example.

SamVerschueren commented 7 years ago

So this was implemented half a year ago? Do I have to do something special in order for this to work?

I think this one can then be closed.

SamVerschueren commented 6 years ago

ping @dlstucki

dlstucki commented 6 years ago

It shouldn't take anything special in order for this to work. Issue can be closed.