Skip to content

Implement background reconnection #2284

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

Merged
merged 7 commits into from
Nov 30, 2020
Merged

Conversation

mgmachado
Copy link
Contributor

Issue this PR solves: #1791

On a connection loss, the client attempts to reconnect up to twice in the background before displaying the reconnection pop-up.

Copy link
Contributor

@nhooyr nhooyr left a comment

Choose a reason for hiding this comment

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

Thank you for contributing @mgmachado, this looks really awesome!

🔥

Going to need approval from @code-asher

}
const logPrefix = commonLogPrefix(this._connectionType, this.reconnectionToken, true);
this._options.logService.info(`${logPrefix} starting reconnecting loop. You can get more information with the trace log level.`);
- this._onDidStateChange.fire(new ConnectionLostEvent());
Copy link
Contributor

Choose a reason for hiding this comment

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

Only concern I have is whether it's ok to not fire this here. Maybe it prevents VS Code from trying to do things on the connection?

But I'm not sure. Just something to note. cc @code-asher

Copy link

Choose a reason for hiding this comment

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

@nhooyr @mgmachado @code-asher
a search in the vscode repo indicates 3 subscribers to PersistentConnectionEventType:

The ExtensionService does act on the ConnectionLost event - so that it can _clearResolvedAuthority. The RemoteExtensionHostEnvironmentUpdater is only interested in the ConnectionGain event - also related to the remote authority.

An alternative approach could be to modify RemoteAgentConnectionStatusListener to handle the events differently. In the same file, it seems like changing VisibleProgress with some sort of delayed activation might be cleaner (after a name change perhaps).

Copy link
Member

@code-asher code-asher left a comment

Choose a reason for hiding this comment

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

Thank you for the PR!

To echo @nhooyr's comment, there can be some unintended consequences if we modify the underlying events.

For example, we rely on these events for our Node proxy service and this could break the service because we need to re-establish the proxy when the connection goes down and comes back up but if that happens in less than three attempts we won't get the necessary events.

Instead we should modify the popup itself, I think. It looks like it's in /lib/vscode/src/vs/workbench/contrib/remote/browser/remote.ts.

Potential implementation: keep a counter that increments each time ReconnectionWait happens and resets to zero every time ConnectionGain happens then use that to determine whether to show the dialogs.

Another potential solution is to change ProgressLocation.Dialog to ProgressLocation.Notification so it appears in the bottom right corner instead of in the middle where it hijacks everything. The advantage here is that it lets the user be more aware of when the connection goes down while still being able to use the editor normally but there's already a persistent connection status in the bottom left so it's probably not a big deal. I'm good either way.

@mgmachado
Copy link
Contributor Author

@choyrim @nhooyr @code-asher thank you for the feedback. I agree that modifying the behavior within the popup is a better approach than suppressing the events.

Should I convert this PR to draft while I work on the suggestions posted here?

@nhooyr
Copy link
Contributor

nhooyr commented Nov 10, 2020

Should I convert this PR to draft while I work on the suggestions posted here?

tbh, I don't really have a preference. I believe the conversion to draft is a somewhat new feature. I suppose it makes sense in this case to indicate this is a WIP.

@mgmachado mgmachado marked this pull request as draft November 10, 2020 22:31
@nhooyr nhooyr added this to the v3.6.4 milestone Nov 13, 2020
@mgmachado
Copy link
Contributor Author

Hey code server devs, I implemented a better solution, but it caused a merge check to fail. I'm working on resolving that - it's the one that tests that the release standalone image can install python and jupyter extensions correctly.

@nhooyr
Copy link
Contributor

nhooyr commented Nov 18, 2020

Hey code server devs, I implemented a better solution, but it caused a merge check to fail. I'm working on resolving that - it's the one that tests that the release standalone image can install python and jupyter extensions correctly.

I believe that failure is unrelated. Feel free to push your changes up and just make sure you're rebased on master.

@mgmachado mgmachado marked this pull request as ready for review November 18, 2020 22:46
@mgmachado
Copy link
Contributor Author

mgmachado commented Nov 18, 2020

The suggestion to convert Dialog to Notification in the ConnectionGain event handler in remote.ts was easy to implement. However, this caused the notifications to keep popping up in the bottom right. This might be ok if the socket drop happens every now and then, but it's distracting when socket drops happen more frequently (in a busy K8s cluster or when accessed through a flaky VPN).

The behavior I've implemented now is: distraction free reconnects the first 2 times, and a Dialog popup at the third attempt to bring the re-connection failure to the user's attention, without suppressing the firing of the connection events.

@choyrim
Copy link

choyrim commented Nov 24, 2020

@nhooyr @code-asher do you still have concerns about this PR after the refactoring?

or do you need us to resolve the latest conflicts before you can review?

Let us know.

@nhooyr
Copy link
Contributor

nhooyr commented Nov 25, 2020

No this looks great! I'll test it today and if all works well, it'll be in the next release!

- if (!visibleProgress) {
- visibleProgress = showProgress(ProgressLocation.Dialog, [reconnectButton, reloadButton]);
+ if (suppressPopup) {
+ hideProgress()
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are these calls necessary? Wouldn't we not have made progress visible if the connection attempt was lower than SHOW_POPUP_ON_ATTEMPT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nhooyr Did you mean "Wouldn't we not have made progress visible if the connection attempt was greater than SHOW_POPUP_ON_ATTEMPT?" Then yes, these calls are redundant. The code could be simplified to

		switch (e.type) {
			case PersistentConnectionEventType.ConnectionLost:
				hideProgress();
				break;

Or did you mean something else?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes sorry, I didn't mean to add the extra not in there.

Yup in that case this looks good to me, will merge. I'll do a follow up commit later to simplify what I can.

Thanks again!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks a lot for the feedback and accepting the PR!

@nhooyr nhooyr modified the milestones: v3.7.5, v3.7.4 Nov 30, 2020
@nhooyr nhooyr changed the base branch from master to reconnect-6fa3 November 30, 2020 07:56
@nhooyr nhooyr changed the title attempt reconnect in the background Implement background reconnection Nov 30, 2020
@nhooyr
Copy link
Contributor

nhooyr commented Nov 30, 2020

Other than that last comment, this looks great!

Thanks for contributing @mgmachado @choyrim

Greatly appreciated 🚀

@nhooyr nhooyr removed this from the v3.7.4 milestone Nov 30, 2020
@nhooyr nhooyr merged commit 70133f6 into coder:reconnect-6fa3 Nov 30, 2020
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.

4 participants