Could you try to run git gc on that specific repository in /var/opt/gitlab/git-data/repository ? Make sure you are using the correct user account don't use root.
Ok, it does sound like the API error may be the root cause here. @ayufan, it looks like the POST request is coming from within the server host (127.0.0.1), not an external CI runner. Is the main project page trying to hit the CI API request?
@torzech
Do you use CI? What is your configuration?
@stanhu This looks like "default nginx host" case. We had problem in Omnibus (should be patched in 8.0.2) when the use of ci_external_url would not create nginx config. I think that in that case the nginx config for previous CI is not created, runners still try to talk to address specified in ci_external_url, but there's no nginx config to handle that address. So, the request are handled by default and only nginx host, the GitLab.
@torzech One thing I don't quite understand is why the project page is getting hung up on the message. Can you open your browser's "Inspect Element" and see if there are any JavaScript errors in the console?
Ok, so it sounds like for some reason import_status in the DB may not be set to the right value for some reason. Do you have access to the DB? For omnibus installations, you can do something like this:
Wow, that's strange. The second one should read finished after the Sidekiq task completes in RepositoryForkWorker. I'm not sure why the DB didn't update in your case. I tried forking large repos on GitLab.com, and things worked fine there.
@DouweM, have you seen any cases where the state machine didn't save to the DB?
You could manually update the DB to "finished" as a workaround for now.
@torzech One possibility is that the DB ran into some validation error for that project record when it attempted to save. Perhaps you could show the output of SELECT * from projects where path = '<YOUR REPO_NAME>'?
I'm baffled by this one. Looks like the records are good, unless there is something in the description/name/path that I'm not seeing.
Does this happen consistently, no matter what you try? The only thing I can suggest is hack /opt/gitlab/embedded/service/gitlab-rails/app/workers/repository_fork_worker.rb and see if we can figure out where it's going wrong:
ifproject.valid_repo?ProjectCacheWorker.perform_async(project.id)logger.info("Import status before: #{project.import_status}")# Addedproject.import_finishlogger.info("Import status after: #{project.import_status}")# Addedelseproject.import_faillogger.error("Project #{id} had an invalid repository after fork")endlogger.info("Import status before save: #{project.import_status}, changed? #{project.changed?}")# Addedproject.savelogger.info("Import status after save: #{project.import_status}, changed? #{project.changed?}")# Addedend
Be sure to run gitlab-ctl restart sidekiq if you do try this. The log messages should appear in the Sidekiq log.
INFO: Booting Sidekiq 3.3.0 with redis options {:url=>"unix:/var/opt/gitlab/redis/redis.socket", :namespace=>"resque:gitlab"}INFO: Running in ruby 2.1.6p336 (2015-04-13 revision 50298) [x86_64-linux]INFO: See LICENSE and the LGPL-3.0 for licensing details.INFO: Upgrade to Sidekiq Pro for more features and support: http://sidekiq.org/proINFO: Starting processing, hit Ctrl-C to stopRepositoryForkWorker JID-a0a4e8f17a470a5b755ec15f INFO: startRepositoryForkWorker JID-a0a4e8f17a470a5b755ec15f INFO: Import status before: startedProjectCacheWorker JID-6ef2b9b88d108e80433c02b1 INFO: startRepositoryForkWorker JID-a0a4e8f17a470a5b755ec15f INFO: Import status after: finishedRepositoryForkWorker JID-a0a4e8f17a470a5b755ec15f INFO: Import status before save: finished, changed? falseRepositoryForkWorker JID-a0a4e8f17a470a5b755ec15f INFO: Import status after save: finished, changed? falseRepositoryForkWorker JID-a0a4e8f17a470a5b755ec15f INFO: done: 0.498 secProjectCacheWorker JID-6ef2b9b88d108e80433c02b1 INFO: done: 0.15 sec
Thanks for trying. It sounds like there is some race condition. Maybe since RepositoryForkWorker and ProjectCacheWorker are both trying to update the same entry in the database that something goes wrong. It may have helped by adding these print statements that the timing changed. I wonder if calling import_finished before we launch the task helps:
@stanhu You may be right about that "race". When I add "sleep 1" between those lines in "if project.valid_repo?", everything works just fine. ;)
ifproject.valid_repo?project.import_finishsleep1ProjectCacheWorker.perform_async(project.id)elseproject.import_faillogger.error("Project #{id} had an invalid repository after fork")end
@torzech Yeah, I think it's an issue with the transaction not being committed at the right time, although I haven't been able to reproduce the same issue despite forking many times.
I've found that I can get one and only one fork per boot of the server. After the server boots up, I can fork a project and it succeeds very quickly. After that, every fork I try is stuck in the "forking in progress" state. Deleting the forks, and recreating them doesn't work until I reboot the server and then I can fork just one project again.
@ngarner_testout Can you check the Sidekiq log and the database as described in the above notes? I just want to confirm that you're seeing the same issue. Can you click around the Files section after you see the "Forking in progress" message?
Yes, I can click on browse through the files of the fork on the GitLab server site, and the bad fork does show up in the list of projects and has the correct amount of disk space showing up for it in the admin area.
Here are all the entries from the sidekiq log that appeared when I tried the most recent fork and had it stall...
@ngarner_testout Ok, looks like the same problem. I can't reproduce it on my end. Can you do me a favor and try to tweak the source code to see if this helps? Here's what to do:
Edit /opt/gitlab/embedded/service/gitlab-rails/app/workers/repository_fork_worker.rb (make a backup if you like) from:
ifproject.valid_repo?ProjectCacheWorker.perform_async(project.id)project.import_finishelseproject.import_faillogger.error("Project #{id} had an invalid repository after fork")end
To:
ifproject.valid_repo?project.import_finishproject.save!ProjectCacheWorker.perform_async(project.id)elseproject.import_faillogger.error("Project #{id} had an invalid repository after fork")end
Run sudo gitlab-ctl restart sidekiq and try again.
Does that help? Please post the Sidekiq logs if there are additional errors. Thanks for your help.
I edited the file and restarted sidekiq as you asked. I was able to fork just one project again afterwards. Here are the lines from the log for the fork that stalled...
So bizzarre. I can't explain why a 1-second delay would help, or why I can't reproduce the issue at all.
The only way I may have a shot at understand what's going on is to look at the SQL logs during this transaction. If one of you is game, you will have to edit:
# See everything in the log (default is :info) config.log_level=:debug
The SQL logs will go into /var/log/gitlab-rails/production.log, so you may want to rename the current one so that you clear out previous data. Restart GitLab completely (sudo gitlab-ctl restart). Then try to fork the repo. We should see updates to import_status like this:
@torzech Thanks! Based on those logs, I think it's clear that the database is never updating the import_status field, and I think I finally realized why: Sidekiq is too fast.
Once someone decides to fork a project, it's a race between Rails and the Sidekiq task. If Rails updates the DB with import_status by the time the Sidekiq task completes the fork, things work fine. Otherwise, Sidekiq attempts to mark the import as finished, but since the DB is not in the started state, nothing happens.
I think the simple fix is to edit add_import_job in /opt/gitlab/embedded/service/gitlab-rails/app/models/project.rb and delay it by 2 seconds:
Can you give that a try and take out the 1-second delay in the worker? You'll probably want to run gitlab-ctl restart to ensure everything is at a good state. Thanks for your help.
FYI, in the meantime, you can work around the problem of stuck repos by setting the import_status field in the projects table to finished. For example:
$ sudo -u gitlab-psql psql -h /var/opt/gitlab/postgresql -d gitlabhq_productionpsql (9.3.5, server 9.2.10)Type "help" for help.gitlabhq_production=# UPDATE projects SET import_status = 'finished' where import_status = 'started' and import_url is NULL;
FYI, GitLab 8.0.3 contains a fix for this. For those of you running into this issue, would you mind upgrading and verifying that forking now works without getting stuck? Thanks @torzech and @ngarner_testout for all your help.
I have installed the version 8.0.3 and the problem for me is not solved.
The workaround in the database doesn't work for me, the command for connecting to postgresql fails.
Hello,
I am trying to fork gitlab-ce on gitlab.com and I am facing the same problem. Of course, I can't perform the work around above because I have no access to the server. Any help would be greatly appreciated