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

Unhandled exception when receiving websocket error #170

Open
orgads opened this issue Mar 7, 2019 · 7 comments
Open

Unhandled exception when receiving websocket error #170

orgads opened this issue Mar 7, 2019 · 7 comments
Assignees
Labels
Bot Services Required for internal Azure reporting. Do not delete. Do not change color. customer-replied-to Required for internal reporting. Do not delete. customer-reported Required for internal Azure reporting. Do not delete.
Milestone

Comments

@orgads
Copy link
Contributor

orgads commented Mar 7, 2019

It happens occasionally when the websocket connection returns 400.

Can be easily reproduced by providing a non-working domain:

    var directLine = new DirectLine({
      secret: <bot-secret>,
      domain: 'https://europe.directline.botframework.com/v3/directline'
    });

Trace:

Error: Unexpected server response: 400                                                           
    at ClientRequest.req.on (E:\Project\node_modules\ws\lib\websocket.js:559:5)                                                                                                       
    at ClientRequest.emit (events.js:159:13)                                                     
    at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:550:21)                
    at HTTPParser.parserOnHeadersComplete (_http_common.js:115:23)                               
    at TLSSocket.socketOnData (_http_client.js:439:20)                                           
    at TLSSocket.emit (events.js:159:13)                                                         
    at addChunk (_stream_readable.js:265:12)                                                     
    at readableAddChunk (_stream_readable.js:252:11)                                             
    at TLSSocket.Readable.push (_stream_readable.js:209:10)                                      
    at TLSWrap.onread (net.js:608:20)                                                            
orgads added a commit to orgads/BotFramework-DirectLineJS that referenced this issue Mar 7, 2019
This prevents unhandled exception on websocket errors.

It *doesn't* propagate the error, since the subscriber is internal,
and it doesn't seem to do anything with it (like notifying the
client via connectionStatus).

Bug: microsoft#170
@orgads
Copy link
Contributor Author

orgads commented Mar 7, 2019

#171 is a partial fix. At least it doesn't crash, but I'm not sure how to proceed from here. I need a way to notify the client. Can you suggest one?

orgads added a commit to orgads/BotFramework-DirectLineJS that referenced this issue Mar 14, 2019
This prevents unhandled exception on websocket errors.

It *doesn't* propagate the error, since the subscriber is internal,
and it doesn't seem to do anything with it (like notifying the
client via connectionStatus).

Bug: microsoft#170
@sgellock sgellock removed the Customer label Aug 8, 2019
orgads added a commit to orgads/BotFramework-DirectLineJS that referenced this issue Sep 26, 2019
This prevents unhandled exception on websocket errors.

It *doesn't* propagate the error, since the subscriber is internal,
and it doesn't seem to do anything with it (like notifying the
client via connectionStatus).

Bug: microsoft#170
compulim pushed a commit that referenced this issue Sep 30, 2019
This prevents unhandled exception on websocket errors.

It *doesn't* propagate the error, since the subscriber is internal,
and it doesn't seem to do anything with it (like notifying the
client via connectionStatus).

Bug: #170
@orgads
Copy link
Contributor Author

orgads commented Jul 28, 2020

Here is a MWE (you need to install nock):

globalThis.XMLHttpRequest = require('xhr2');
globalThis.WebSocket = require('ws');
import * as nock from 'nock';
import { DirectLine } from 'botframework-directlinejs';

const conversation = {
  conversationId: '123',
  token: '456',
  streamUrl: 'wss://google.com/'
};
nock('https://directline.botframework.com')
  .post('/v3/directline/conversations')
  .reply(200, JSON.stringify(conversation));
const directLine = new DirectLine({ secret: '1234' });
directLine.activity$
  .subscribe(
    activity => {
      if (activity.type === 'message')
        console.log("received activity ", activity.text);
    },
    error => {
      console.error(error);
    }
  );

@cwhitten cwhitten added the R11 Release 11 - November 15th, 2020 label Aug 11, 2020
@cwhitten cwhitten removed the R11 Release 11 - November 15th, 2020 label Nov 12, 2020
@compulim
Copy link
Collaborator

compulim commented Jan 4, 2021

Hi @orgads, this is recently fixed in #324. You should start seeing this fixed in @0.13.2-master.c6ecb71.

Please let us know if it resolves the issue. Thanks.

@orgads
Copy link
Contributor Author

orgads commented Jan 14, 2021

Hi. Sorry for the delay.

I tested it now. It doesn't crash, but I also don't get an error event. Reproduces with the MWE I posted above.

Do I need something else for capturing errors?

@orgads
Copy link
Contributor Author

orgads commented Feb 7, 2021

@compulim ping

@compulim
Copy link
Collaborator

compulim commented Feb 11, 2021

You are correct. The PR #324 was a rework of your #171 without triggering the bug in RxJS and also without logging out the error in the console.

Currently, DLJS was designed not to send out any events on intermittent connection errors.

Looking at directLine.ts:359, this is the enumerable for connection status:

export enum ConnectionStatus {
    Uninitialized,              // the status when the DirectLine object is first created/constructed
    Connecting,                 // currently trying to connect to the conversation
    Online,                     // successfully connected to the conversation. Connection is healthy so far as we know.
    ExpiredToken,               // last operation errored out with an expired token. Possibly waiting for someone to supply a new one.
    FailedToConnect,            // the initial attempt to connect to the conversation failed. No recovery possible.
    Ended                       // the bot ended the conversation
}

Both FailedToConnect and Ended doesn't handle the case of intermediate errors, which reconnection will take place and recovery could be possible.

Connecting looks good to me as a candidate for status-ing about reconnections. Since we debut the Web Socket feature, we never set it to Connecting after initial connection. So this will be change in API behavior.

@cwhitten and @willportnoy tl;dr the customer is asking for a signal or event to indicate when reconnection took place. After some research, I think we could reuse the Connecting enum to indicate a reconnection. But this will also introduce a behavioral change in our API.

In W3C Server-Sent Events, they also used CONNECTING to indicate both initial connection and subsequent reconnections.

We could have an opt-in/out flag. I prefer an opt-out flag because this behavior is aligned with where the industry to heading towards.

Any thoughts?

image

Update: Looking at our source code today, I am a bit worried about setting a new value to connectionStatus$ may impact our current logic at checkConnection(), which is a function that is called on every REST call (including WS reconnection). Probably need some time to understand how it can be done and what tests we need to add to ensure current behavior is not affected.

@compulim compulim added this to the R13 milestone Feb 17, 2021
@orgads
Copy link
Contributor Author

orgads commented Feb 17, 2021

cc @yoshigev

@Kaiqb Kaiqb removed this from the R13 milestone Mar 26, 2021
@cleemullins cleemullins added Bot Services Required for internal Azure reporting. Do not delete. Do not change color. customer-replied-to Required for internal reporting. Do not delete. customer-reported Required for internal Azure reporting. Do not delete. labels Jun 8, 2021
@cleemullins cleemullins added this to the R15 milestone Jun 8, 2021
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 Required for internal reporting. Do not delete. customer-reported Required for internal Azure reporting. Do not delete.
Projects
None yet
Development

No branches or pull requests

7 participants