Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DirectLineStreaming: unhandled rejection from connectWithRetryAsync in activity$ #398

Closed
compulim opened this issue Apr 4, 2023 · 0 comments · Fixed by #399
Closed

DirectLineStreaming: unhandled rejection from connectWithRetryAsync in activity$ #398

compulim opened this issue Apr 4, 2023 · 0 comments · Fixed by #399

Comments

@compulim
Copy link
Collaborator

compulim commented Apr 4, 2023

When subscribing activity$, it will call connectWithRetryAsync(), which is an async function of return type Promise<void>.

image

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant