Skip to content

[sql-14] sessions: atomic session creation #980

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 2 commits into from
Feb 26, 2025

Conversation

ellemouton
Copy link
Member

@ellemouton ellemouton commented Feb 17, 2025

See #979 for more context.

In this PR, we do the refactor to make session creation happen in 1 atomic DB transaction as described in the issue above.

Fixes #979

req.DevServer, uniquePermissions, caveats, nil, false, nil,
session.PrivacyFlags{},
)
if err != nil {
return nil, fmt.Errorf("error creating new session: %v", err)
}

if err := s.cfg.db.CreateSession(sess); err != nil {
sess, err = s.cfg.db.CreateSession(sess.ID)
Copy link
Member Author

Choose a reason for hiding this comment

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

note: in this follow up, we add a way to do this in one go for normal (non-autopilot) sessions

Copy link
Contributor

@ViktorTigerstrom ViktorTigerstrom left a comment

Choose a reason for hiding this comment

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

Generally looks good 🚀! Leaving one comment regarding state enforcement during session revoking that I believe we should fix :)

Copy link
Contributor

@ViktorTigerstrom ViktorTigerstrom left a comment

Choose a reason for hiding this comment

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

Looks good 🚀! Still need to clarify regarding the same comment I left above though, but other than that, this looks good to go from my end 🔥

Copy link
Contributor

@ViktorTigerstrom ViktorTigerstrom left a comment

Choose a reason for hiding this comment

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

Niiiiiiiiiiiiice! uTACK LGTM 🔥!

Copy link
Contributor

@bitromortac bitromortac left a comment

Choose a reason for hiding this comment

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

LGTM, nice clean-up ⚡

In this commit, we let StateReserved be the new initial state of a
session for when NewSession is called. We then do predicate checks for
linked sessions along with unique session alias (ID) and priv key
derivations all under the same DB transaction in NewSession.

ShiftState then moves a session to StateCreated. Only in StateCreated
does a session become usable.

With this change, we no longer need to ensure atomic session creation by
acquiring the `sessRegMu` mutex in the session RPC server.
This was used to check that all linked sessions are no longer
active before attempting to register an autopilot session. But this is
no longer needed since this is done within NewSession.
@ellemouton ellemouton merged commit aa8080d into lightninglabs:master Feb 26, 2025
18 of 21 checks passed
@ellemouton ellemouton deleted the sql14Sessions6 branch February 26, 2025 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-changelog This PR is does not require a release notes entry sql-ize
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[sqli-ze] sessions: atomic session creation
3 participants