Bitbucket Server or Data Center displays a 404 error when opening a repository
プラットフォームについて: Server および Data Center のみ。この記事は、Server および Data Center プラットフォームのアトラシアン製品にのみ適用されます。
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Fisheye および Crucible は除く
要約
When attempting to access a repository, Bitbucket displays a 404 error page stating that "No repository with slug <REPOSITORY_SLUG> exists in the project <PROJECT_NAME>.
"
Bitbucket may also throw the 404 error "No default branch is defined."
診断
Check repository permissions
- Ensure the user receiving the error has at least
Read
access to the Repository; if the user has a direct URL link to the repository and they cannot access it, they should be greeted with the same 404 error message. This can be verified by an Admin. - If the Admin confirms that the repository is showing the same error for all users, then continue to the
Cause
section below.
Check application logging
The access logs (atlassian-bitbucket-access*
) will record a 404
status code for the output of the request:
Check out our KB How To Read Bitbucket Server Log Format for details on the output request below.
10.110.228.157,127.0.0.1 | https | o@1C0SBJXx1097x2129267x1 | user.name | 2021-02-23 18:17:20,797 | "GET /projects/PROJ/repos/repo1/browse HTTP/1.0" |
"" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36" | 404 | 0 | 13842 | - | 26 | 16ee0we |
The profiler logs (atlassian-bitbucket-profiler
*), if profiling is enabled, will fail to render the page as shown below:
2021-02-23 18:17:20,796 | http-nio-7990-exec-53 | @1C0SBJXx1097x2129267x1 | user.name | 16ee0we
[26.5ms] - "GET /projects/PROJ/repos/repo1/browse HTTP/1.0"
[1.3ms] - ApplicationUser com.atlassian.bitbucket.user.UserService.getUserById(int)
[3.6ms] - Page com.atlassian.bitbucket.user.UserService.findGroupsByUser(String,PageRequest)
[16.3ms] - Render soy: bitbucket.internal.page.errors.errors.repo404
[6.3ms] - void com.atlassian.plugin.webresource.WebResourceManager.includeResources(Writer,UrlMode)
Note the entry in the above log snippet that says "bitbucket.internal.page.errors.errors.repo404"
原因
There are 3 known causes for this issue as listed below.
Cause #1: Repository Permissions
The impacted user(s) lack the necessary repository permissions to access the repository.
Cause #2: Filesystem and Database Mismatch
This is usually caused by restoring from a backup that was not taken correctly.
In this case, either the Database or the Filesystem (git repositories on the Shared home folder) will be out of sync causing orphaned objects.
Cause #3: Corrupt Database Indexes
The database indexes for the repository
or project
tables have become corrupt and need to be recreated.
ソリューション
Solution for the Cause #1: Repository Permissions
If the impacted user is meant to have access to the repository, assign the user the appropriate repository permission.
Solution for the Cause #2: Filesystem and Database Mismatch
Solution #1
Enable Bitbucket Integrity Check.
This is only available for Bitbucket Data Center licenses. Please refer to Solution #2 for Server licenses.
To enable:
Add the following entry to your
<Bitbucket-home>/shared/
bitbucket.properties
file:disaster.recovery=true
- Perform an application restart for the change to take effect.
The Integrity Check will then identify and correct pull requests as well as create the necessary file structure for newly created repositories. See Bitbucket Integrity Check for more details. If you don't wish to run full integrity checks, please refer to Solution #2.
Solution #2
If you wish to delete the repository in order to clear the error, please execute the below REST API to delete the remaining metadata of the broken repository from the database. This method works for both Server & Datacenter licenses. Replace {..} with values specific to your instance.
curl -X DELETE -u {adminusername} -H "Content-Type: application/json" -H "Accept: application/json" {Bitbucket-Base-URL}/projects/{Project-Key}/repos/{Repository-Name}
For example, please refer to the sample data below:
Sample Project Key: DEMO
Sample Repo Name: deploy-scripts
Bitbucket Base URL: http://example.com
Admin User: admin
Example command to delete the sample repository.
curl -X DELETE -u admin -H "Content-Type: application/json" -H "Accept: application/json" http://example.com/projects/DEMO/repos/deploy-scripts
You can now recreate the repository if required.
Solution for the Cause #3: Corrupt Database Indexes
Re-index the repository and project tables in Bitbucket's database. This can be done while the application is running, however, it could lead to some performance degradation whilst it runs.
Please make sure you adapt the statements to the appropriate syntax for your database.
The re-index statements should look similar to the below:
REINDEX TABLE project;
REINDEX TABLE repository;
Please make sure you run these commands as the same database user that Bitbucket is configured to use.
For example, with PostgreSQL, you could run the following two psql
commands on the system where the database server is running:
psql -d <bitbucket_db> -U <bitbucket_db_user> -c "REINDEX TABLE project;"
psql -d <bitbucket_db> -U <bitbucket_db_user> -c "REINDEX TABLE repository;"
If this does not resolve the issue, you will need to perform a full re-index of the database. We advise that you schedule downtime for Bitbucket as it will cause severe performance degradation while the full re-index is running.
The full re-index statement should look similar to the below:
REINDEX DATABASE <bitbucket_db>;