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

Cannot detect absence of network #102

Open
chadxz opened this issue Oct 30, 2018 · 5 comments
Open

Cannot detect absence of network #102

chadxz opened this issue Oct 30, 2018 · 5 comments

Comments

@chadxz
Copy link
Owner

chadxz commented Oct 30, 2018

Originally reported in #101

If you start to connect to a remote server in the absence of a network, errors can also not be caught without debug. They simply have nowhere to catch as there is no websocket object. This object appears only when there is a connection, if I understand correctly.

@chadxz
Copy link
Owner Author

chadxz commented Oct 31, 2018

@GolDiV I will restate the problem to make sure I understand what you are saying.

When creating an instance of the websocket client in the absence of a network connection, you're unable to intercept the error.

I've got a test for this scenario. https://github.com/chadxz/awry/blob/master/test/events/ReconnectingWebsocket.spec.js#L66-L96

It simulates an error prior to a connection by making the validation fail when connecting to the server.

It sounds like that test isn't an accurate representation of your issue though.

Can you verify that I understand your problem correctly?

@GolDiV
Copy link

GolDiV commented Oct 31, 2018

I experimented a bit and came to the following conclusion. In your test input parameter (verifyClient) set correctly, but it seemed to me you are testing is not quite the same event. I will try to show it an example:

const events = awry.Events.connect({
    app: 'app',
    url: host,
    username: user,
    password: password
  })
  events.on('open', () => {
    console.log('Connection ON')
    pingpong(events._ws)
  })
  events.on('disconnected', (err) => {
    console.log('Connection OFF. Error: ')
    console.log(err)
  })
  events.on('reconnected', () => {
    console.log('Reconnected')
    pingpong(events._ws)
  })
  events.on('close', () => console.log('Connection closed'))
  events.on('error', () => console.log('Connection error'))

  events._ws.on('error', (err) => console.log(err))

  function pingpong (ws) {
    setInterval(() => ws.ping(() => {}), 3000)
  }

I have a remote server asterisk so to break the connection I pull out the network cable.
Case one:
I disconnect my network cable and start script.
The event events._ws.on('error', ...) is triggered and its triggered only once. But in debug mode i see some attempts to reconnect.
Then I connect network cable and the event events.on('open',...) is triggered.
Case two
I connected with server normally. Event events.on('open',...) is triggered. Then i disconnect cable.
By reason of function ping, the client learns about the disconnection, and event events.on('disconnected',...) is triggered. After turn on network event events.on('reconnected',...) is triggered.
And in both cases event events.on('error',...) never works.

@chadxz
Copy link
Owner Author

chadxz commented Oct 31, 2018

For each case can you describe what you expected to be the behavior?

@GolDiV
Copy link

GolDiV commented Oct 31, 2018

Ideally, I want to listen to errors by one listener such as event.on ('error',...) and receive all connection error events from it.

@GolDiV
Copy link

GolDiV commented Nov 1, 2018

Hi Chad! I think I found the solution. Into file ReconnectingWebSocket.js (master) I add into row 109 next code:

this.emit("error", { err, reconnect: this._reconnect, numRetries })

After that listener events.on('error',...) catches all connection errors, including failed attempts to reconnect

@chadxz chadxz added help wanted semver-minor Contains backward-compatible features and removed semver-minor Contains backward-compatible features labels May 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants