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

Prevents infinite WebSocket reconnection spam on subsequent token expiration signals #127

Merged
merged 2 commits into from
Dec 21, 2018

Conversation

cwhitten
Copy link
Member

Currently when a token expires and the browser is using WebSockets, this client library will infinitely attempt to reconnect in very fast iterations to the DirectLine server and receive 403's forever.

A couple things introduced here to address this issue:

  • the ability to monitor cycles of a particular ConnectionStatus and provide a fallback when triggered.
  • Jest, because testing is important and this project has none.

Copy link
Collaborator

@compulim compulim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ckkashyap can you run thru a logic check on this one?

connectionStatusFrom: ConnectionStatus,
connectionStatusTo: ConnectionStatus,
maxAttempts = 5
) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation.

Suggested change
) {
) {

return (status: ConnectionStatus): ConnectionStatus => {
if (status === connectionStatusFrom && currStatus === status) {
if (attempts >= maxAttempts - 1) {
attempts = 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semi-colon.

Suggested change
attempts = 0
attempts = 0;

let attempts = 0;
let currStatus = null;
return (status: ConnectionStatus): ConnectionStatus => {
if (status === connectionStatusFrom && currStatus === status) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about doing two-if on one line?

Suggested change
if (status === connectionStatusFrom && currStatus === status) {
if (status === connectionStatusFrom && currStatus === status && attempts >= maxAttempts - 1) {

connectionStatusTo: ConnectionStatus,
maxAttempts = 5
) {
let attempts = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we initially set attempts = 1, then we can get rid of the maxAttempts - 1 below.


test('#setConnectionStatusFallback', () => {
const { DirectLine } = DirectLineExport;
expect(typeof DirectLine.prototype.setConnectionStatusFallback).toBe('function')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about moving this line below so we can do

Suggested change
expect(typeof DirectLine.prototype.setConnectionStatusFallback).toBe('function')
expect(typeof setConnectionStatusFallback).toBe('function');

test('#setConnectionStatusFallback', () => {
const { DirectLine } = DirectLineExport;
expect(typeof DirectLine.prototype.setConnectionStatusFallback).toBe('function')
const { setConnectionStatusFallback } = DirectLine.prototype
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semi-colon (and below).

Suggested change
const { setConnectionStatusFallback } = DirectLine.prototype
const { setConnectionStatusFallback } = DirectLine.prototype;

const { setConnectionStatusFallback } = DirectLine.prototype
const testFallback = setConnectionStatusFallback(0, 1)
let idx = 4
while(idx--) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space before parenthesis.

Suggested change
while(idx--) {
while (idx--) {

// fallback will be triggered
expect(testFallback(0)).toBe(1)
idx = 4
while(idx--) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
while(idx--) {
while (idx--) {

"json",
"node"
],
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New empty line before EOF.

@compulim
Copy link
Collaborator

compulim commented Dec 21, 2018

FYI, me and @ckkashyap were building the test harness (integration tests) here, https://github.com/compulim/BotFramework-DirectLineJS/blob/preview/packages/test-harness/src/createServer.test.ts.

We aren't moving it in yet, so I am good for the current work.

"jsx",
"json",
"node"
],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comma.

Suggested change
],
]

"js",
"jsx",
"json",
"node"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.node seems less used, but I am fine to keep it here.

Copy link
Collaborator

@ckkashyap ckkashyap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@cwhitten cwhitten merged commit f01f9ff into master Dec 21, 2018
@cwhitten cwhitten deleted the websocket-spam branch December 21, 2018 21:21
cwhitten added a commit that referenced this pull request Dec 21, 2018
…iration signals (#127)

* Prevents infinite WebSocket reconnection spam on subsequent token expiration signals
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 this pull request may close these issues.

3 participants