Skip to content

fix: restore previous session on coder server --dev - #1821

Merged
f0ssel merged 3 commits into
mainfrom
f0ssel/restore-dev-session
May 27, 2022
Merged

f0ssel merged 3 commits into
mainfrom
f0ssel/restore-dev-session

Conversation

@f0ssel

@f0ssel f0ssel commented May 26, 2022

Copy link
Copy Markdown
Member

Fixes #1747

@f0ssel
f0ssel requested a review from mafredri May 26, 2022 23:00
@f0ssel
f0ssel requested a review from a team May 26, 2022 23:04
Comment thread cli/server.go Outdated

oldURL, err := cfg.URL().Read()
if err != nil {
return nil, xerrors.Errorf("write local url: %w", err)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This would fail if an old session didn't exist, right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

fixed

@mafredri mafredri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for taking a look at this issue! I think Kyle's comment warrants a small change but other than that, LGTM!

Comment thread cli/server.go Outdated
}
}
err = createFirstUser(cmd, client, config, devUserEmail, devUserPassword)
cleanupSession, err := createFirstUser(logger, cmd, client, config, devUserEmail, devUserPassword)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggestion: Would restore/restorePreviousSession be more descriptive here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done

Comment thread cli/server.go Outdated
if err != nil {
logger.Error(cmd.Context(), "failed to read current session token", slog.Error(err))
return
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thought: Do we need to consider cases where the user has tried the logout flow or ran coder login against the dev server? If so we could consider renaming the files to {url,session}.bak, and if those files are present on exit, (or startup), restore them. Perhaps even dev tokens could be a different format from non-dev, that way we could always identify if a restore case is appropriate or not.

Being able to restore on startup would also cover cases where the server is killed instead of graciously exited.

I'm probably overthinking this though, this change alone should help alleviate the most common cases.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think as a first pass I'd rather not try to guess, because I could see devs spending quite a while trying to figure out what's wrong before they realize it's the session. Currently if it's different that we would expect we just choose "do nothing", and I'm down to add more logic here as we use it and run into cases.

@f0ssel
f0ssel enabled auto-merge (squash) May 27, 2022 16:53
@f0ssel
f0ssel merged commit 8a5277e into main May 27, 2022
@f0ssel
f0ssel deleted the f0ssel/restore-dev-session branch May 27, 2022 17:02
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.

Bug: Running code server --dev overwrites credentials

4 participants