-
Notifications
You must be signed in to change notification settings - Fork 128
Closed
Description
When subscribing activity$, it will call connectWithRetryAsync(), which is an async function of return type Promise<void>.
However, the Promise returned was never handled, i.e. no catch() or try-catch block.
In Node.js, when a Promise reject without catching it and the control is back to the event-loop, Node.js will terminate the process immediately.
Code snippet.
const { DirectLineStreaming } = require('../lib/directLineStreaming');
try {
const directLine = new DirectLineStreaming({
// Intentionally connecting to wrong domain.
domain: 'https://bing.com/',
secret: 'not-a-secret'
});
directLine.connectionStatus$.subscribe(value => {
console.log('Connection status:', value);
});
// Kick off connection.
directLine.activity$.subscribe(() => {});
} catch (error) {
console.log('Never caught here, because the rejection is inside the subscription logic of activity$.');
}
setTimeout(() => console.log('Exited peacefully.'), 5000);When DLJS failed to connect, it should handle all exceptions/rejections so the process can reach the "Exited peacefully" point.
However, today, because it does not handle rejection of connectWithRetryAsync. Thus, the "Exited peacefully" point was never reach. In the console:
Connection status: 0
Connection status: 1
Failed to connect Error: Unable to connect client to Node transport.
/workspaces/BotFramework-DirectLineJS/node_modules/botframework-streaming/lib/webSocket/nodeWebSocketClient.js:63
throw new Error('Unable to connect client to Node transport.');
^
Error: Unable to connect client to Node transport.
at WebSocketClient.<anonymous> (/workspaces/BotFramework-DirectLineJS/node_modules/botframework-streaming/lib/webSocket/nodeWebSocketClient.js:63:23)
at Generator.throw (<anonymous>)
at rejected (/workspaces/BotFramework-DirectLineJS/node_modules/botframework-streaming/lib/webSocket/nodeWebSocketClient.js:13:65)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Node.js v19.7.0
When it works, it should console out:
Connection status: 0
Connection status: 1
Failed to connect Error: Unable to connect client to Node transport.
Connection status: 4
Exited peacefully.
(4 means failed to connect)
(tagging @orgads)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
