Get offline notification

Hi,

Is there a way to get a callback in a Theia extension when Theia goes offline ?

Thanks!

[original thread by Julien Eluard]

@jeluard from a theia extension you can listen to the onStatusChange event: https://github.com/eclipse-theia/theia/blob/1ca3ec37c079a6b316278cf292609653e57b8151/packages/core/src/browser/connection-status-service.ts#L39

[Julien Eluard]

Thanks!

[Julien Eluard]

It looks like onStatusChange is triggered when a tab browser is not active after a couple seconds. At least on chrome/osx. Select a different tab, select another app, wait 5 seconds and OFFLINE is sent.

Is that the expected behaviour?

@jeluard I’ve noticed the same thing when quickly testing. I believe it is because we have a timer (idle) which causes us to fire the status change event:

this.timer = this.setTimeout(() => {
  console.log(`No activity for ${this.options.offlineTimeout} ms. We are offline.`);
  this.updateStatus(false);
}, this.options.offlineTimeout);

I see the following log:

root INFO No activity for 5000 ms. We are offline.

Perhaps there is an improvement to be made in this area, thank you for reporting the behavior.

Or it means that chromes suspends activities of the background tab and does not send messages over WS anymore or setTimeout behaves differently for such tabs.

[Julien Eluard]

Right it looks like setTimeout slows down when in an inactive tab. WebSockets apparently still work as expected.

[amiramw]

Does it make sense to change the pings logic so inactive tab doesn’t send those pings at all?

I am not sure, if there is not ping, a user can loose all debugging sessions and so on. So probably no.

[amiramw]

@anton-kosyakov what is the expectation for debug sessions, I once opened https://github.com/eclipse-theia/theia/issues/4591 for them being lost on brief disconnections. This means that already today they are lost when chrome tab is not active as according to the above there are disconnects.

I cannot say anything according to the above. There still can be a ping, but the status reported bogusly since timeout behaves differently.

the debug sessions is only an example, we will have to consider how it affects other services as well.

[amiramw]

what about if we need to disconnect sessions after some time of inactivity. do you see this as a contribution or should we rebind FrontendConnectionStatusService in our extension?

I don’t know. I will need to debug it to learn more first. I don’t like that ping rely on timing of setTimeout, maybe there is a way to rework it first without relying on such timings. But I don’t think we need to stop sending ping if the tab is not active.

[shahar-h]

@anton-kosyakov We are looking for a way to identify if incoming message is a ping response or not, so we can identify user inactivity.
Do you see any issue with adding message content to onIncomingMessageActivity event? Or maybe do you have some other proposal?

AbstractConnectionStatusService.onStatusChange should fire with ONLINE when ping is responded

Why do you want to know it?

[shahar-h]

We want stop sending ping messages to backend when user is inactive after some predefined time. In order to detect user inactivity I thought about reading incoming traffic and exclude ping responses somehow.
Other direction can be to detect user inactivity by listening to mousemove and keypress events, but then I’m not sure how to listen to webviews events. Maybe do you have other idea?

All webview keys are delivered to main window: https://github.com/eclipse-theia/theia/blob/fd5894ecb6ae2a69fba2773c9eeec8f97ebd7649/packages/plugin-ext/src/main/browser/webview/webview.ts#L279

I wonder what would happen when a user left a terminal to run some important task, but connection times out because there was not any interactions.