LivePersonInc / node-agent-sdk

LivePerson Agent Messaging SDK for NodeJS
MIT License
49 stars 79 forks source link

There is a possibility that It isn't catching "open" at LiveEngage server failure. #135

Open tubone24 opened 3 years ago

tubone24 commented 3 years ago

Background

When using AgentSDK.js to connect to LiveEngage server, there was an issue that occurred after the "init" process was started, but the action was frozen.

What's the problem?

The behavior got stuck in the following areas, as I guessed from the our server's logs.

https://github.com/LivePersonInc/node-agent-sdk/blob/master/lib/AgentSDK.js#L323

In transport.js, when creating a websocket instance in the code, it was implemented by receiving "open" from the websocket instances and emitting it as it is.

https://github.com/LivePersonInc/node-agent-sdk/blob/master/lib/Transport.js#L62

However, due to some effects (e.g., LiveEngage Server failure), there was the case that didn't emit "open" from a websocket instance because of not connected when creating the instance, so that our code was stopped working.

How should you fix this?

I thin it is preferable to use "setTimeout" to force the connection to be dropped if the "open" is not emitted for a certain period of time, and reconnect it.

And also I haven't tested it myself yet, but there seems to be a timeout option in Websocket. (I'm sorry that I haven't checked it properly, so it may be a meaningless option.) https://github.com/websockets/ws/blob/3d5066a7cad9fe3176002916aeda720a7b5ee419/lib/websocket.js#L470