# Server cache not found when target branch of a PR isn't the main one

**URL:** <https://community.sonarsource.com/t/server-cache-not-found-when-target-branch-of-a-pr-isnt-the-main-one/105982>\
**Category:** SonarQube Cloud\
**Created:** [December 13, 2023, 5:22pm UTC](https://community.sonarsource.com/t/server-cache-not-found-when-target-branch-of-a-pr-isnt-the-main-one/105982 "2023-12-13T17:22:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ADGB](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/adgb/32/47700_2.png) [@ADGB](https://community.sonarsource.com/u/ADGB)\
**Post date:** [December 13, 2023, 5:22pm UTC](https://community.sonarsource.com/t/server-cache-not-found-when-target-branch-of-a-pr-isnt-the-main-one/105982/1 "2023-12-13T17:22:42Z")

</div>

Hi.

We run SonarCloud C++ analysis relying on the server cache. It works fine when a pull request #1 from `branch-1` is opened toward `master`, but not when another pull request #2 is opened from `branch-2` toward `branch-1` (which happens quite often with “stacked PR” workflow).

According to [the documentation](https://docs.sonarsource.com/sonarcloud/advanced-setup/languages/c-c-objective-c/#analysis-cache):

> The cached analysis results speed up subsequent analyses by analyzing the only things that have changed between the two analyses.
> 
> - For [branch analysis](https://docs.sonarsource.com/sonarcloud/enriching/branch-analysis/), an analysis cache is stored on the server per branch.
> - For pull request analysis, the cache of the base branch is used and not persisted.
> - If no cache is found, the cache of the Main branch is used.

As such, I’m expecting the pull request #2 to use the cache from the main branch as a fallback. However, this is not what happen. The entire project is analyzed again, because the cache was not found.

Here is an extract from the logs of pull request #2:

```log
INFO: Load branch configuration
INFO: Detected analysis for pull request '2' targeting 'branch-1'
INFO: Auto-configuring pull request 2
INFO: The base branch 'branch-1' is only analyzed as a pull request. Using its base instead: 'master'
INFO: Load branch configuration (done) | time=368ms
[...]
INFO: Found empty cache on server
INFO: [pool-6-thread-1] /opt/atlassian/pipelines/agent/build/project/main.cpp

```

In comparison, a pull request opened directly toward `master` works fine:

```log
INFO: Load branch configuration
INFO: Detected analysis for pull request '1' targeting 'master'
INFO: Auto-configuring pull request 1
INFO: Load branch configuration (done) | time=285ms
[...]
INFO: Loading cache from: server
INFO: Cache hit for: /opt/atlassian/pipelines/agent/build/project/main.cpp

```

Please, could someone explain why pull requests directed toward short-lived branches aren’t using the cache from `master` as a fallback?

_Attachments:_

- [sonarcloud.log](https://community.sonarsource.com/uploads/short-url/vkY42bfD72KYkNGZFNnJO5e8wgp.log) (7.3 KB)
- [sonar-project.properties](https://community.sonarsource.com/uploads/short-url/1c4mTjmxfFZC5MybFLS4Sut7cZ6.txt) (508 Bytes)

---

<div class="post-metadata">

**Author:** ![anita.stanisz](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/anita.stanisz/32/39153_2.png) [@anita.stanisz](https://community.sonarsource.com/u/anita.stanisz)\
**Post date:** [December 20, 2023, 1:38pm UTC](https://community.sonarsource.com/t/server-cache-not-found-when-target-branch-of-a-pr-isnt-the-main-one/105982/5 "2023-12-20T13:38:49Z")

</div>

Hi @ADGB

Welcome to the community! 🙂

I need some time to investigate this behaviour and to clarify the ‘why’. I’ll come back to you once I know more.

Anita

---

<div class="post-metadata">

**Author:** ![ADGB](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/adgb/32/47700_2.png) [@ADGB](https://community.sonarsource.com/u/ADGB)\
**Post date:** [January 22, 2024, 9:22am UTC](https://community.sonarsource.com/t/server-cache-not-found-when-target-branch-of-a-pr-isnt-the-main-one/105982/11 "2024-01-22T09:22:22Z")

</div>

Hi there.

Is there anything I can do on my side to help investigate the issue?

I’m still facing this curious behavior with stacked PR. This causes the analysis to last for more than 1 hour instead of 5 min with the cache. Our Bitbucket pipelines are piling up and finally failing due to a lack of available resources.

---

<div class="post-metadata">

**Author:** ![anita.stanisz](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/anita.stanisz/32/39153_2.png) [@anita.stanisz](https://community.sonarsource.com/u/anita.stanisz)\
**Post date:** [January 22, 2024, 10:14am UTC](https://community.sonarsource.com/t/server-cache-not-found-when-target-branch-of-a-pr-isnt-the-main-one/105982/12 "2024-01-22T10:14:18Z")

</div>

Hi @ADGB

I’m really sorry for the delay, and your issue wasn’t forgotten 🙂

It’s a bug, I was able to reproduce the problem and created an internal ticket to fix it.  
As it impacts you a lot, we’ll prioritize the fix, however, I can’t promise any date when it will be tackled.

Anita

---

<div class="post-metadata">

**Author:** ![ADGB](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/adgb/32/47700_2.png) [@ADGB](https://community.sonarsource.com/u/ADGB)\
**Post date:** [January 22, 2024, 10:26am UTC](https://community.sonarsource.com/t/server-cache-not-found-when-target-branch-of-a-pr-isnt-the-main-one/105982/14 "2024-01-22T10:26:29Z")

</div>

Great, glad you were able to reproduce it and thanks for the update!

---

<div class="post-metadata">

**Author:** ![anita.stanisz](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/anita.stanisz/32/39153_2.png) [@anita.stanisz](https://community.sonarsource.com/u/anita.stanisz)\
**Post date:** [January 29, 2024, 9:36am UTC](https://community.sonarsource.com/t/server-cache-not-found-when-target-branch-of-a-pr-isnt-the-main-one/105982/15 "2024-01-29T09:36:29Z")

</div>

Hi @ADGB

The fix was just deployed, could you test to see whether it solves your problem?

Anita

---

<div class="post-metadata">

**Author:** ![ADGB](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/adgb/32/47700_2.png) [@ADGB](https://community.sonarsource.com/u/ADGB)\
**Post date:** [January 29, 2024, 11:26am UTC](https://community.sonarsource.com/t/server-cache-not-found-when-target-branch-of-a-pr-isnt-the-main-one/105982/16 "2024-01-29T11:26:29Z")

</div>

@anita.stanisz I can confirm that the cache from the main branch is now used as fallback, and the analysis is much faster:

```auto
INFO: Load branch configuration
INFO: Detected analysis for pull request '2' targeting 'branch-1'
INFO: Auto-configuring pull request 2
INFO: The base branch 'branch-1' is only analyzed as a pull request. Using its base instead: 'master'
INFO: Load branch configuration (done) | time=584ms
[...]
INFO: Loading cache from: server
INFO: Cache hit for: /opt/atlassian/pipelines/agent/build/project/main.cpp

```

Thank you very much! 👍

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/system/32/31083_2.png) [@system](https://community.sonarsource.com/u/system)\
**Post date:** [February 9, 2024, 3:14pm UTC](https://community.sonarsource.com/t/server-cache-not-found-when-target-branch-of-a-pr-isnt-the-main-one/105982/20 "2024-02-09T15:14:31Z")

</div>

Closed on February 9, 2024, 3:14pm UTC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
