Skip to content

Git Locker issue while discard and pull is fixed#37300

Closed
shanid544 wants to merge 1 commit intoappsmithorg:releasefrom
shanid544:fix/git-lock-error-while-discard-and-pull
Closed

Git Locker issue while discard and pull is fixed#37300
shanid544 wants to merge 1 commit intoappsmithorg:releasefrom
shanid544:fix/git-lock-error-while-discard-and-pull

Conversation

@shanid544
Copy link
Contributor

@shanid544 shanid544 commented Nov 8, 2024

Description

When there are uncommitted changes in a Git-connected app, and the user attempts to pull upstream changes, a "Git lock" error appears. This prevents the user from discarding or pulling changes, causing workflow disruptions.

Steps to Reproduce:
Create a git connected app
Create a page and let it stay as an uncommitted change
Make some changes to the application via the remote repo
Try to commit the uncommitted changes from step 2
Notice that git lock error is seen on any discard/pull actions subsequently

Updated Steps to Reproduce:
Create a Git-connected app.
Create a new branch from the main branch.
Create a page with uncommitted changes.
Make additional changes to the app in the remote repository on the same branch.
Attempt to commit the uncommitted changes from Step 3.
Notice the Git lock error when trying to discard or pull changes.

Root Cause Analysis:
The issue occurs when a commit command attempts to acquire a lock on the file system, which it then saves to Redis using baseArtifactId/baseAppId as the key.
The lock has a duration of 3 minutes with 20 retries and a 1-second interval between retries.
The commit command obtains this lock before the discard action is attempted. If the user quickly tries to discard, the lock remains active, and they must wait up to 3 minutes for it to be released.

Solution
Call releaseFileLock() from CommonGitServiceCEImpl.java before throwing the GIT_UPSTREAM_CHANGES error.

`if (pushResult.contains("REJECTED_NONFASTFORWARD")) {
            return addAnalyticsForGitOperation(
                            AnalyticsEvents.GIT_PUSH,
                            artifact,
                            AppsmithError.GIT_UPSTREAM_CHANGES.getErrorType(),
                            AppsmithError.GIT_UPSTREAM_CHANGES.getMessage(),
                            gitMetadata.getIsRepoPrivate())
                   @ .then(releaseFileLock(artifact.getGitArtifactMetadata().getDefaultArtifactId()))
                    .flatMap(application1 -> Mono.error(new AppsmithException(AppsmithError.GIT_UPSTREAM_CHANGES)));`

Fixes #36781

Automation

/ok-to-test tags=""

🔍 Cypress test results

Caution

If you modify the content in this section, you are likely to disrupt the CI result for your PR.

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Introduced methods for retrieving Git documentation URLs and managing branches.
    • Enhanced branch management capabilities with improved conflict resolution.
  • Bug Fixes

    • Improved error handling for Git operations, including detailed messages for failures.
  • Analytics

    • Expanded analytics integration for monitoring branch protection changes and Git operations.
  • Refactor

    • Refactored methods for better readability and maintainability, particularly in artifact import processes.

@shanid544 shanid544 requested a review from a team as a code owner November 8, 2024 10:20
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 8, 2024

Walkthrough

The changes in CommonGitServiceCEImpl.java introduce new methods and enhance existing functionalities related to Git operations. Key updates include the addition of methods for retrieving documentation URLs, managing branches, and improved error handling during Git operations. The code has been refactored for better clarity, and analytics integration has been expanded to monitor Git operations more effectively.

Changes

Files Change Summary
app/server/appsmith-server/src/main/java/com/appsmith/server/git/common/CommonGitServiceCEImpl.java - Added methods: getGitDocUrls, listBranchForArtifact, updateProtectedBranches.
- Updated createBranch and mergeBranch for enhanced error handling.
- Improved error handling in pullArtifact and commitArtifact.
- Refactored importArtifactFromGit for clarity.
- Updated method signatures for importArtifactFromGit.

Assessment against linked issues

Objective Addressed Explanation
Handle Git lock error when uncommitted changes are present (#36781)

Possibly related PRs

  • chore: refactored git status #34270: Involves refactoring the getStatus method in CommonGitServiceCEImpl.java, related to the overall Git operations and error handling improvements.

Suggested labels

Bug, Production, Needs Triaging, Git Product, Medium, Git Platform Pod

Suggested reviewers

  • nidhi-nair
  • sondermanish

🎉 In the realm of Git, where branches entwine,
New methods emerge, oh how they shine!
With error checks and clarity in sight,
Pulling and pushing, everything feels right.
Analytics now dance, tracking each move,
In this code evolution, we all surely approve! 🌿


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (4)
app/server/appsmith-server/src/main/java/com/appsmith/server/git/common/CommonGitServiceCEImpl.java (4)

Line range hint 256-260: Simplify null checks in isBaseGitMetadataInvalid method

The null checks for gitArtifactMetadata can be simplified for clarity.

Consider simplifying the method as:

- return Optional.ofNullable(gitArtifactMetadata).isEmpty()
-         || Optional.ofNullable(gitArtifactMetadata.getGitAuth()).isEmpty()
-         || StringUtils.isEmptyOrNull(gitArtifactMetadata.getGitAuth().getPrivateKey())
-         || StringUtils.isEmptyOrNull(gitArtifactMetadata.getGitAuth().getPublicKey());
+ return gitArtifactMetadata == null
+         || gitArtifactMetadata.getGitAuth() == null
+         || StringUtils.isEmptyOrNull(gitArtifactMetadata.getGitAuth().getPrivateKey())
+         || StringUtils.isEmptyOrNull(gitArtifactMetadata.getGitAuth().getPublicKey());

Line range hint 970-986: Ensure file locks are always released in mergeBranch

If an error occurs after acquiring the file lock in the mergeBranch method, the lock may not be released, potentially causing deadlocks.

Use doFinally to ensure the file lock is released regardless of the outcome:

 .flatMap(tuple -> {
     // existing code
 })
-.onErrorResume(
-        error -> releaseFileLock(baseArtifactId).then(Mono.error(error)));
+.doFinally(signalType -> releaseFileLock(baseArtifactId));

Line range hint 313-350: Release file locks in error cases in pullArtifact

In the pullArtifact method, if an error occurs after acquiring the file lock, it may not be released.

Modify error handling to ensure the lock is released:

 .flatMap(tuple -> {
     // existing code
 })
-.name(GitSpan.OPS_PULL)
-.tap(Micrometer.observation(observationRegistry));
+.onErrorResume(error -> releaseFileLock(baseArtifact.getGitArtifactMetadata().getDefaultArtifactId())
+        .then(Mono.error(error)))
+.name(GitSpan.OPS_PULL)
+.tap(Micrometer.observation(observationRegistry));

Line range hint 1290-1300: Ensure file locks are released in pushArtifactErrorRecovery

In pushArtifactErrorRecovery, the file lock may not be released if an error occurs.

Ensure the lock is released in all cases:

 return Mono.just(pushResult)
+    .doFinally(signalType -> releaseFileLock(artifact.getGitArtifactMetadata().getDefaultArtifactId()));
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between da6d497 and f1e4d52.

📒 Files selected for processing (1)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/git/common/CommonGitServiceCEImpl.java (1 hunks)

@github-actions
Copy link

This PR has not seen activitiy for a while. It will be closed in 7 days unless further activity is detected.

@github-actions github-actions bot added the Stale label Nov 15, 2024
@github-actions
Copy link

This PR has been closed because of inactivity.

@github-actions github-actions bot closed this Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Git lock error is seen and upstream changes cannot be pulled when uncommitted changes are present

2 participants