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

[Streaming, Preview] New connections cause existing connections to break #1408

Closed
henryjenkins opened this issue Nov 13, 2019 · 4 comments · Fixed by microsoft/BotBuilder-Samples#1979
Assignees
Labels
Bot Services Required for internal Azure reporting. Do not delete. Do not change color. customer-replied-to Indicates that the team has replied to the issue reported by the customer. Do not delete. customer-reported Issue is created by anyone that is not a collaborator in the repository. P0 Must Fix. Release-blocker

Comments

@henryjenkins
Copy link

henryjenkins commented Nov 13, 2019

Versions

using botframework-4.6.0-preview2
on nodejs 10.15.3

Describe the bug

Given a directline-speech client is connected to a bot via a Bot Channel Registration in Azure,
when a new directline-speech client connects,
then the existing client will no longer receive any activities

To Reproduce

Steps to reproduce the behaviour:

Expected behavior

The JS Bot adapter should support multiple concurrent connections

Additional context

I tried the same test with the DotNet C# version of the same sample bot (05), and it does not suffer from the same problem.
[bug]

@henryjenkins henryjenkins changed the title New connections cause existing connet New connections cause existing connections to break Nov 13, 2019
@CoHealer CoHealer added Bot Services Required for internal Azure reporting. Do not delete. Do not change color. customer-reported Issue is created by anyone that is not a collaborator in the repository. labels Nov 13, 2019
@CoHealer CoHealer self-assigned this Nov 13, 2019
@axelsrz
Copy link
Member

axelsrz commented Nov 13, 2019

@carlosscastro could you take a look at this please?

@stevengum
Copy link
Member

stevengum commented Nov 14, 2019

Closing as a fix was merged into the 4.6-preview-staging branch via #1412

per: @stevengum the bug wasn't actually fixed in this PR. Investigation ongoing.

@stevengum
Copy link
Member

Currently, the singleton Adapter pattern used in the samples doesn't work for supporting multiple WebSocket connections.

botbuilder-samples/experimental/directline-speech/javascript_nodejs/02.echo-bot - 651f405

const adapter = new BotFrameworkAdapter({
    appId: process.env.MicrosoftAppId,
    appPassword: process.env.MicrosoftAppPassword,
    enableWebSockets: true
});

const myBot = new EchoBot();

server.post('/api/messages', (req, res) => {
    adapter.processActivity(req, res, async (context) => {
        // Route to main dialog.
        await myBot.run(context);
    });
});

// Listen for GET requests to the same route to accept Upgrade requests for Streaming.
server.get('/api/messages', (req, res) => {
    adapter.processActivity(req, res, async (context) => {
        // After connecting via WebSocket, run this logic for every request sent over
        // the WebSocket connection.
        await myBot.run(context);
    });
});

In Node.js the streaming implementation relies on creating a new Adapter for every request.

The correct pattern for supporting multiple websocket connections is to create a new BotFrameworkAdapter for every Upgrade request. The code below works in 4.6.0-preview2.

// Listen for GET requests to the same route to accept Upgrade requests for Streaming.
server.get('/api/messages', (req, res) => {
    // Create an adapter scoped to this WebSocket connection to allow storing session
    // data.
    const streamingAdapter = new BotFrameworkAdapter({
        appId: process.env.MicrosoftAppId,
        appPassword: process.env.MicrosoftAppPassword,
        enableWebSockets: true
    });
    streamingAdapter.processActivity(req, res, async (context) => {
        // After connecting via WebSocket, run this logic for every request sent over
        // the WebSocket connection.
        await myBot.run(context);
    });
});

For Named Pipes, a singleton adapter is usable because only one Named Pipe connection is supported from the App Service Extension.

@stevengum
Copy link
Member

The combined code snippets above could look like the following:

const settings = {
    appId: process.env.MicrosoftAppId,
    appPassword: process.env.MicrosoftAppPassword,
    enableWebSockets: true
};

const adapter = new BotFrameworkAdapter(settings);
const myBot = new EchoBot();

server.post('/api/messages', (req, res) => {
    adapter.processActivity(req, res, async (context) => {
        await myBot.run(context);
    });
});

// Listen for GET requests to the same route to accept Upgrade requests for Streaming.
server.get('/api/messages', (req, res) => {
    // Create an adapter scoped to this WebSocket connection to allow storing session
    // data.
    const streamingAdapter = new BotFrameworkAdapter(settings);
    streamingAdapter.processActivity(req, res, async (context) => {
        // After connecting via WebSocket, run this logic for every request sent over
        // the WebSocket connection.
        await myBot.run(context);
    });
});

@stevengum stevengum changed the title New connections cause existing connections to break [Streaming, Preview] New connections cause existing connections to break Nov 14, 2019
@axelsrz axelsrz added the customer-replied-to Indicates that the team has replied to the issue reported by the customer. Do not delete. label Nov 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bot Services Required for internal Azure reporting. Do not delete. Do not change color. customer-replied-to Indicates that the team has replied to the issue reported by the customer. Do not delete. customer-reported Issue is created by anyone that is not a collaborator in the repository. P0 Must Fix. Release-blocker
Projects
None yet
5 participants