Skip to content

UsersService.upsertFromGithub creates the User and the GithubAccount in two separate transactions #789

Closed

Description

@chonilius

The new-identity path saves twice (src/users/users.service.ts:126-146):

    let user = this.userRepo.create({ username, email, ... });
    user = await this.userRepo.save(user);

    account = this.githubAccountRepo.create({ githubId: input.githubId, ..., userId: user.id });
    await this.githubAccountRepo.save(account);

Each save commits independently.

Why it matters: if the second save fails — a constraint violation, a connection drop, a pod eviction — a User row exists with no GithubAccount. That state is unrecoverable through the normal flow: the next sign-in looks the identity up by githubId (:48-51), finds nothing, takes the new-identity path again, hits the username collision, and creates a second user as login-1. Repeat sign-ins produce login-2, login-3, and so on, while the original orphaned row holds the username the user expects. The user can never reach their original account, and nothing cleans up the orphans.

generateUniqueUsername's 100-iteration loop (:149-161) is evidence this has been hit: the only way to accumulate that many collisions on one login is repeated failures of this kind.

Fix: wrap both writes in dataSource.transaction. While there, the loop issues one query per candidate — replace it with a single query for existing usernames matching the prefix, or catch the unique violation and retry with a random suffix.

Activity

  1. added
    bug
    on Nov 12, 2026
  2. added
    Stellar Wave
    on Nov 19, 2026
  3. OgbuKingsley166 commented on Nov 19, 2026

    @OgbuKingsley166

    @OgbuKingsley166 has applied to work on this issue as part of the Stellar Wave Program's 11th wave.

    Hi there, I'd like to contribute to this.

    I'm a software engineer with strong experience in JavaScript and building scalable web applications. I'm comfortable working across the stack, writing clean, maintainable code, and collaborating in open source environments.

    I understand what's being asked here and I'm confident I can implement this correctly and efficiently.

    Looking forward to contributing — please assign this issue to me.

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @OgbuKingsley166 to this issue.

  4. maikNeta commented on Nov 19, 2026

    @maikNeta
    Contributor

    @maikNeta has applied to work on this issue as part of the Stellar Wave Program's 11th wave.

    hi maintainer let me fix this please

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @maikNeta to this issue.

  5. drips-wave commented on Nov 19, 2026

    @drips-wave

    Congratulations, @maikNeta! 🎉 Your application was accepted by the repo's maintainers, and the issue is due on November 25, 2026.

    🧑‍💻 @maikNeta: Please resolve the issue such that the repo's maintainers have enough time to review your contribution before the due date. You'll earn Points for completing the issue on-time, which will make you eligible for a share of the Stellar Wave Program's reward pool.

    Warning

    When opening a PR, please link it to this issue to ensure it gets tracked accurately. Points are awarded when this issue is marked as completed by the maintainer.

    🤠 Repo maintainers: Please keep an eye on the contributor's progress and review their work before the due date. You can manage this issue, including adjusting its complexity and points, here.

    🌊 Happy Wave 🌊

  6. added a commit that references this issue on Nov 20, 2026
    c29a86d
  7. drips-wave commented on Nov 20, 2026

    @drips-wave

    This issue has been completed by @maikNeta as part of the Stellar Wave Program's 11th Wave 🥳

    😎 @maikNeta: You earned 200 Points for completing this issue! Once the Wave's rewards are finalized, you'll be eligible for a percentage of the Wave's reward pool based on the percentage of total points you've earned. Learn more here. You can also Leave a review to share your experience working on this issue.

    🧑‍💻 Repo maintainers: How'd the contributor do? Leave a review to share your experience working with them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Stellar Wavebug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions