Skip to content

feat: cache plugin manifest files with bbb-web - #24220

Merged
antobinary merged 23 commits into
bigbluebutton:v3.0.x-developfrom
GuiLeme:bbb-web-cache-manifest
May 11, 2026
Merged

antobinary merged 23 commits into
bigbluebutton:v3.0.x-developfrom
GuiLeme:bbb-web-cache-manifest

Conversation

@GuiLeme

@GuiLeme GuiLeme commented Nov 11, 2025 •

Copy link
Copy Markdown
Contributor

What does this PR do?

  • It adds a new logic to cache plugin manifests when downloaded via bbb-web;
  • It creares a configurable flag to enable this feature or not pluginManifestCacheEnabled;
  • It periodically refreshes the cached files. The interval is configurable via luginManifestCacheRefreshIntervalMinutes=60
  • It is disabled for default.

Closes Issue(s)

Closes bigbluebutton/bigbluebutton-html-plugin-sdk#223

Motivation

This PR is meant to enhance speed of creating a meeting, if all the plugins are cached, there is no need to fetch their files and therefore no latency is added.

How to test

  • Create a meeting with a plugin (make sure pluginManifestCacheEnabled is set to true in bigbluebutton.properties);
  • Look up for the cached file under /var/bigbluebutton/plugin-manifests-cache;
  • Create another meeting with the same plugin(s), and see in bbb-web logs "Found cache for plugin ...";

@GuiLeme
GuiLeme requested a review from gustavotrott November 11, 2025 14:38
@coderabbitai

coderabbitai Bot commented Nov 11, 2025 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Adds an optional, date-based plugin-manifest caching layer and wires it into meeting creation. MeetingService gains injectable fields and setters for pluginManifestCacheEnabled and pluginUtils, and delegates manifest retrieval/validation to PluginUtils. PluginUtils implements per-URL locking, cache path generation (date-based, MD5 hashed names under configurable base dir), read/write cache helpers, an HTTP fetcher, checksum validation, and JSON parsing to extract plugin name. Configuration properties and Spring wiring were added, and a daily cron job line removes the cache directory.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant MeetingService
    participant PluginUtils
    participant FileSystem
    participant ExternalURL

    rect rgba(232,245,233,0.5)
    Note over MeetingService,PluginUtils: Cache-enabled conditional flow
    end

    Client->>MeetingService: Create meeting (with plugin manifests)
    MeetingService->>PluginUtils: getRawPluginManifestContent(manifest)
    PluginUtils->>PluginUtils: obtain per-URL lock
    alt Cache enabled -> check cache
        PluginUtils->>FileSystem: Read cached manifest (date-hashed path)
        alt Cache hit
            FileSystem-->>PluginUtils: cached content
        else Cache miss
            FileSystem-->>PluginUtils: null
            PluginUtils->>ExternalURL: HTTP GET manifest
            ExternalURL-->>PluginUtils: manifest content
            PluginUtils->>PluginUtils: validate checksum & parse name
            PluginUtils->>FileSystem: write cached manifest (if valid)
        end
    else Cache disabled
        PluginUtils->>ExternalURL: HTTP GET manifest
        ExternalURL-->>PluginUtils: manifest content
    end
    PluginUtils-->>MeetingService: pluginManifestContent
    MeetingService->>MeetingService: parse JSON, verify name/checksum, substitute template
    MeetingService-->>Client: Return meeting creation response

    rect rgba(255,235,238,0.5)
    Note over FileSystem: Daily cleanup job removes /var/bigbluebutton/plugin-manifests-cache/
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: cache plugin manifest files with bbb-web' clearly and concisely summarizes the primary change—adding caching functionality for plugin manifests in bbb-web.
Linked Issues check ✅ Passed The PR implements all core objectives from issue #223: adds manifest caching mechanism [#223], introduces pluginManifestCacheEnabled config flag [#223], stores cache under /var/bigbluebutton/plugin-manifests-cache/ [#223], uses URL-based hashing with date-based invalidation [#223], and includes daily cleanup via cron job [#223].
Out of Scope Changes check ✅ Passed All code changes are directly aligned with the caching feature requirements: MeetingService and PluginUtils refactoring support cache lookup/storage, configuration properties enable/configure caching, Spring bean wiring integrates the feature, and the cron job performs routine cache cleanup.
Description check ✅ Passed The pull request description clearly explains the feature (plugin manifest caching), configuration options, testing steps, and directly aligns with the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dcd3d0b and 3362015.

📒 Files selected for processing (5)
  • bbb-common-web/src/main/java/org/bigbluebutton/api/MeetingService.java (5 hunks)
  • bbb-common-web/src/main/java/org/bigbluebutton/api/util/PluginUtils.java (3 hunks)
  • bigbluebutton-config/cron.daily/bigbluebutton (1 hunks)
  • bigbluebutton-web/grails-app/conf/bigbluebutton.properties (1 hunks)
  • bigbluebutton-web/grails-app/conf/spring/resources.xml (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
bbb-common-web/src/main/java/org/bigbluebutton/api/MeetingService.java (1)
bbb-common-web/src/main/java/org/bigbluebutton/api/util/PluginUtils.java (1)
  • PluginUtils (29-239)
bbb-common-web/src/main/java/org/bigbluebutton/api/util/PluginUtils.java (2)
bbb-common-web/src/main/java/org/bigbluebutton/api/ParamsProcessorUtil.java (1)
  • ParamsProcessorUtil (49-1835)
bbb-common-web/src/main/java/org/bigbluebutton/api/domain/PluginManifest.java (1)
  • PluginManifest (3-32)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build-package (bbb-web)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
bbb-common-web/src/main/java/org/bigbluebutton/api/MeetingService.java (1)

381-441: Handle race condition in placeholder file creation.

When two threads simultaneously experience a cache miss for the same plugin URL, both will attempt to call createEmptyCacheFileFrom at line 386. The second thread's call will throw FileAlreadyExistsException (caught as IOException at line 453), causing the plugin to fail with a misleading "I/O error" message instead of gracefully handling the race condition.

Modify PluginUtils.createEmptyCacheFileFrom (lines 195-200) to catch and suppress FileAlreadyExistsException, since the placeholder already exists and serves its purpose—preventing duplicate fetches.

♻️ Duplicate comments (1)
bbb-common-web/src/main/java/org/bigbluebutton/api/util/PluginUtils.java (1)

195-200: Handle race condition in placeholder creation.

This is similar to the past review comment. When two threads simultaneously experience a cache miss for the same plugin, both will invoke createEmptyCacheFileFrom. The second call will hit FileAlreadyExistsException at line 199, causing the entire manifest fetch to fail in MeetingService.

Apply this diff to tolerate concurrent placeholder creation:

+import java.nio.file.FileAlreadyExistsException;
+
 public static void createEmptyCacheFileFrom(String pluginManifestUrlString) throws IOException {
     Path cachedPluginManifestPath = getCachedPluginManifestPath(pluginManifestUrlString);
     Path cacheDir = getCachedPluginsBaseDirectory();
     Files.createDirectories(cacheDir);
-    Files.createFile(cachedPluginManifestPath);
+    try {
+        Files.createFile(cachedPluginManifestPath);
+    } catch (FileAlreadyExistsException e) {
+        // Another thread already created the placeholder; that's fine
+    }
 }
🧹 Nitpick comments (2)
bbb-common-web/src/main/java/org/bigbluebutton/api/MeetingService.java (1)

21-21: Prefer explicit imports over wildcard.

Wildcard imports obscure which classes are actually used and can lead to naming conflicts.

Replace the wildcard with explicit imports:

-import java.io.*;
+import java.io.IOException;
bbb-common-web/src/main/java/org/bigbluebutton/api/util/PluginUtils.java (1)

225-232: Reuse the directory helper method.

Line 230 creates a new Path from the constant, but you already have getCachedPluginsBaseDirectory() for this purpose.

Apply this diff:

 public static Path getCachedPluginManifestPath(String pluginManifestUrlString) {
     LocalDate date = LocalDate.now();
     String formatted = date.format(formatter);

     String hashedPluginManifestUrl = DigestUtils.sha256Hex(pluginManifestUrlString + formatted);
-    Path cacheDir = Paths.get(CACHED_PLUGINS_BASE_DIRECTORY);
+    Path cacheDir = getCachedPluginsBaseDirectory();
     return cacheDir.resolve(hashedPluginManifestUrl + ".json");
 }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3362015 and 97e7aed.

📒 Files selected for processing (2)
  • bbb-common-web/src/main/java/org/bigbluebutton/api/MeetingService.java (5 hunks)
  • bbb-common-web/src/main/java/org/bigbluebutton/api/util/PluginUtils.java (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
bbb-common-web/src/main/java/org/bigbluebutton/api/util/PluginUtils.java (2)
bbb-common-web/src/main/java/org/bigbluebutton/api/ParamsProcessorUtil.java (1)
  • ParamsProcessorUtil (49-1835)
bbb-common-web/src/main/java/org/bigbluebutton/api/domain/PluginManifest.java (1)
  • PluginManifest (3-32)
bbb-common-web/src/main/java/org/bigbluebutton/api/MeetingService.java (1)
bbb-common-web/src/main/java/org/bigbluebutton/api/util/PluginUtils.java (1)
  • PluginUtils (29-241)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build-package (bbb-web)
🔇 Additional comments (4)
bbb-common-web/src/main/java/org/bigbluebutton/api/MeetingService.java (1)

1602-1604: Setter looks correct.

The setter follows standard conventions. If you change the field to primitive boolean per the earlier comment, update this parameter to match or explicitly handle null (e.g., treat as false).

bbb-common-web/src/main/java/org/bigbluebutton/api/util/PluginUtils.java (3)

180-193: Cache read logic is sound.

The method correctly checks for file existence before reading and returns null on cache miss. The TOCTOU gap between the existence check and read is acceptable since the caller handles IOException.


202-210: Concurrent writes are acceptable.

If multiple threads fetch and save the same manifest, both writeString calls will succeed; the last writer wins. Since they're writing identical content, this is safe.


221-223: Helper method is straightforward.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
bigbluebutton-config/cron.daily/bigbluebutton (1)

147-147: Consider adding a configuration option for flexibility.

The unconditional invocation is reasonable for a date-based cache cleanup. However, following the pattern of remove_raw_of_recordings_without_marks (lines 87-88), you might consider adding a comment noting that this can be disabled if needed, or introduce a config variable for this cleanup task.

Example (similar to line 88):

+# Enabled by default; comment to disable.
 remove_plugin_manifests_cache
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 97e7aed and f4d5e66.

📒 Files selected for processing (3)
  • bbb-common-web/src/main/java/org/bigbluebutton/api/MeetingService.java (5 hunks)
  • bbb-common-web/src/main/java/org/bigbluebutton/api/util/PluginUtils.java (3 hunks)
  • bigbluebutton-config/cron.daily/bigbluebutton (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • bbb-common-web/src/main/java/org/bigbluebutton/api/MeetingService.java
  • bbb-common-web/src/main/java/org/bigbluebutton/api/util/PluginUtils.java
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build-package (bbb-web)
🔇 Additional comments (1)
bigbluebutton-config/cron.daily/bigbluebutton (1)

139-145: LGTM! Implementation addresses previous feedback.

The function correctly removes the entire cache directory (as suggested in the past review comment), includes a proper existence check, and follows the established cleanup patterns in this file. The logging provides good visibility, and the quoted variable prevents potential issues with word splitting.

@GuiLeme
GuiLeme requested a review from gustavotrott November 11, 2025 20:47

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (2)
bbb-common-web/src/main/java/org/bigbluebutton/api/util/PluginUtils.java (2)

40-40: Make cache directory constant immutable.

This issue was previously flagged: CACHED_PLUGINS_BASE_DIRECTORY should be declared as public static final String to prevent runtime modification.

Apply this diff:

-public static String CACHED_PLUGINS_BASE_DIRECTORY = "/var/bigbluebutton/plugin-manifests-cache/";
+public static final String CACHED_PLUGINS_BASE_DIRECTORY = "/var/bigbluebutton/plugin-manifests-cache/";

220-227: Check HTTP status code before returning body.

This issue was previously flagged: the method returns the response body for any HTTP status, including error responses (404, 500, etc.), which can lead to parsing failures.

Apply this diff to validate the response:

 public static String fetchPluginManifestContentFromUrl(
         String pluginManifestUrlString
 ) throws IOException, InterruptedException {
     HttpClient client = HttpClient.newHttpClient();
     HttpRequest request = HttpRequest.newBuilder(URI.create(pluginManifestUrlString)).GET().build();
     HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
+    if (response.statusCode() < 200 || response.statusCode() >= 300) {
+        throw new IOException("HTTP " + response.statusCode() + " when fetching " + pluginManifestUrlString);
+    }
     return response.body();
 }
🧹 Nitpick comments (4)
bbb-common-web/src/main/java/org/bigbluebutton/api/util/PluginUtils.java (4)

204-206: Optimize cache existence check to avoid reading file content.

Currently, this method reads the entire cached file just to verify existence. For large manifests, this is wasteful when only a boolean check is needed.

Apply this diff to check existence without reading content:

 public static boolean hasPluginManifestContentCacheFile(String pluginManifestUrlString) throws IOException {
-    return getPluginManifestContentFromCache(pluginManifestUrlString) != null;
+    synchronized (getLockFor(pluginManifestUrlString)) {
+        Path cachedPluginManifestPath = getCachedPluginManifestPath(pluginManifestUrlString);
+        return Files.isRegularFile(cachedPluginManifestPath);
+    }
 }

233-240: Use getCachedPluginsBaseDirectory() for consistency.

Line 238 duplicates the path construction logic that's already available in getCachedPluginsBaseDirectory().

Apply this diff:

 public static Path getCachedPluginManifestPath(String pluginManifestUrlString) {
     LocalDate date = LocalDate.now();
     String formatted = date.format(formatter);
 
     String hashedPluginManifestUrl = DigestUtils.sha256Hex(pluginManifestUrlString + formatted);
-    Path cacheDir = Paths.get(CACHED_PLUGINS_BASE_DIRECTORY);
+    Path cacheDir = getCachedPluginsBaseDirectory();
     return cacheDir.resolve(hashedPluginManifestUrl + ".json");
 }

220-227: Configure HTTP timeouts to prevent thread exhaustion.

The HttpClient is created without timeout configuration. If a plugin manifest server is slow or unresponsive, threads will block indefinitely.

Apply this diff to add sensible timeouts:

+import java.time.Duration;
+
 public static String fetchPluginManifestContentFromUrl(
         String pluginManifestUrlString
 ) throws IOException, InterruptedException {
-    HttpClient client = HttpClient.newHttpClient();
-    HttpRequest request = HttpRequest.newBuilder(URI.create(pluginManifestUrlString)).GET().build();
+    HttpClient client = HttpClient.newBuilder()
+            .connectTimeout(Duration.ofSeconds(10))
+            .build();
+    HttpRequest request = HttpRequest.newBuilder(URI.create(pluginManifestUrlString))
+            .GET()
+            .timeout(Duration.ofSeconds(30))
+            .build();
     HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
     if (response.statusCode() < 200 || response.statusCode() >= 300) {
         throw new IOException("HTTP " + response.statusCode() + " when fetching " + pluginManifestUrlString);
     }
     return response.body();
 }

208-218: Consider adding size limits when writing cached manifests.

Currently, there's no limit on the size of cached content. A malicious or misconfigured plugin could provide a very large "manifest" that fills disk space.

Reference the maxPluginManifestsFetchUrlPayloadSize pattern used in ParamsProcessorUtil.processPluginManifestsFetchUrl (see relevant code snippets) to validate manifest size before caching. Consider adding a configuration property for the maximum cached manifest size and checking content length before writing.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f4d5e66 and ed31c49.

📒 Files selected for processing (1)
  • bbb-common-web/src/main/java/org/bigbluebutton/api/util/PluginUtils.java (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
bbb-common-web/src/main/java/org/bigbluebutton/api/util/PluginUtils.java (2)
bbb-common-web/src/main/java/org/bigbluebutton/api/ParamsProcessorUtil.java (1)
  • ParamsProcessorUtil (49-1835)
bbb-common-web/src/main/java/org/bigbluebutton/api/domain/PluginManifest.java (1)
  • PluginManifest (3-32)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build-package (bbb-web)
🔇 Additional comments (3)
bbb-common-web/src/main/java/org/bigbluebutton/api/util/PluginUtils.java (3)

41-46: LGTM: Thread-safe per-URL locking.

The date formatter and per-URL lock mechanism using ConcurrentHashMap.computeIfAbsent provide thread-safe cache operations without global contention.


187-202: LGTM: Cache retrieval is thread-safe and handles misses correctly.

The synchronized block, regular-file check, and null-on-miss pattern are all appropriate.


208-218: LGTM: Cache write properly creates directories and handles overwrites.

The synchronized block, directory creation, and atomic write operation are correct. Files.createDirectories is idempotent, and overwriting existing cache entries is the expected behavior.

@sonarqubecloud

Copy link
Copy Markdown

@antobinary antobinary added this to the Release 3.0 milestone Nov 28, 2025
@github-actions

Copy link
Copy Markdown

This pull request has conflicts ☹
Please resolve those so we can review the pull request.
Thanks.

@gustavotrott gustavotrott left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's working properly. But I left a few suggestions.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (3)
bbb-common-web/src/main/java/org/bigbluebutton/api/util/PluginUtils.java (2)

238-245: Validate HTTP status codes before returning manifest body

fetchPluginManifestContentFromUrl currently returns the response body for any HTTP status. If the server responds with 404/500 (HTML error page, maintenance message, etc.), the caller attempts to parse it as JSON and only later fails, which makes errors less clear and may complicate debugging.

Consider checking response.statusCode() and treating non-2xx as an I/O error:

     HttpClient client = HttpClient.newHttpClient();
     HttpRequest request = HttpRequest.newBuilder(URI.create(pluginManifestUrlString)).GET().build();
     HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
-    return response.body();
+    int status = response.statusCode();
+    if (status < 200 || status >= 300) {
+        throw new IOException("HTTP " + status + " when fetching " + pluginManifestUrlString);
+    }
+    return response.body();

This allows the caller to surface a clearer error path for HTTP failures instead of a downstream JSON parse error.


5-5: MD5 is sufficient (and faster) for cache file naming

For getCachedPluginManifestPath, the hash is only used to derive a filesystem-friendly name, not for security or integrity. Using DigestUtils.sha256Hex(...) is stronger than necessary and slightly more expensive.

Switching to MD5 keeps collision risk negligible in this context and reduces cost:

-        String hashedPluginManifestUrl = DigestUtils.sha256Hex(pluginManifestUrlString + formatted);
+        String hashedPluginManifestUrl = DigestUtils.md5Hex(pluginManifestUrlString + formatted);

Since this only affects opaque filenames in the cache directory, the change is internal and doesn’t alter behavior from the caller’s perspective.

Also applies to: 255-257

bbb-common-web/src/main/java/org/bigbluebutton/api/MeetingService.java (1)

90-90: Avoid NullPointerException on pluginManifestCacheEnabled and prefer primitive boolean

pluginManifestCacheEnabled is a boxed Boolean and used directly in conditionals (e.g., Line 382: if (pluginManifestCacheEnabled) {), which will NPE if the property is not set or injected as null. Given this is a feature flag, defaulting to false is safer and more explicit.

Consider switching to a primitive with a safe default and updating the setter accordingly:

-  private Boolean pluginManifestCacheEnabled;
+  private boolean pluginManifestCacheEnabled = false;
...
-    public void setPluginManifestCacheEnabled(Boolean pluginManifestCacheEnabled) {
-        this.pluginManifestCacheEnabled = pluginManifestCacheEnabled;
-    }
+  public void setPluginManifestCacheEnabled(boolean pluginManifestCacheEnabled) {
+    this.pluginManifestCacheEnabled = pluginManifestCacheEnabled;
+  }

This keeps the call sites simple and removes the risk of an unexpected NPE during manifest fetching.

Also applies to: 381-387, 1601-1603

🧹 Nitpick comments (1)
bbb-common-web/src/main/java/org/bigbluebutton/api/util/PluginUtils.java (1)

44-50: Cache coordination mostly solid; consider lighter existence checks and single check+save path

The per-URL locking and date-based hash path generation look good, but a couple of details can be streamlined:

  • hasPluginManifestContentCacheFile(...) calls getPluginManifestContentFromCache(...), which reads the entire file into memory just to check existence. For large numbers of requests this is unnecessary overhead.
  • The existence check (has...) and write (save...) are done in separate calls; under concurrency, two threads can both see a miss and both write the same file. It’s safe, but wasteful.

You could simplify and make this more efficient by:

  • Letting hasPluginManifestContentCacheFile just check for existence under the per-URL lock without reading content:
public static boolean hasPluginManifestContentCacheFile(String pluginManifestUrlString) throws IOException {
    synchronized (getLockFor(pluginManifestUrlString)) {
        Path cachedPluginManifestPath = getCachedPluginManifestPath(pluginManifestUrlString);
        return Files.isRegularFile(cachedPluginManifestPath);
    }
}
  • Or even better, moving the existence check inside savePluginManifestContentInCache (still under the same lock) so callers simply say “save” and the method no-ops when the file already exists.

This keeps the locking model simple, avoids redundant file reads, and further reduces the chance of duplicate writes.

Also applies to: 205-236, 247-258

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3d637d0 and 5036e48.

📒 Files selected for processing (2)
  • bbb-common-web/src/main/java/org/bigbluebutton/api/MeetingService.java (5 hunks)
  • bbb-common-web/src/main/java/org/bigbluebutton/api/util/PluginUtils.java (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
bbb-common-web/src/main/java/org/bigbluebutton/api/util/PluginUtils.java (3)
bbb-common-web/src/main/java/org/bigbluebutton/api/domain/PluginManifest.java (1)
  • PluginManifest (3-32)
bbb-common-web/src/main/java/org/bigbluebutton/api/exception/PluginMalformedParametersException.java (1)
  • PluginMalformedParametersException (5-27)
bbb-common-web/src/main/java/org/bigbluebutton/api/exception/PluginMetadataException.java (1)
  • PluginMetadataException (3-25)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build-package (bbb-html5)
  • GitHub Check: build-package (bbb-web)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🧹 Nitpick comments (1)
bbb-common-web/src/main/java/org/bigbluebutton/api/util/PluginUtils.java (1)

227-235: Consider an atomic cache write.

Files.writeString writes in place. If the JVM crashes mid-write, a truncated or partial JSON file remains and will be served on the next request (the read path doesn't re-validate cached content against the checksum before returning). Writing to a sibling temp file and using Files.move(..., ATOMIC_MOVE, REPLACE_EXISTING) avoids torn writes and concurrent reader/writer interleavings on platforms that support it.

♻️ Proposed sketch
-        Path cachedPluginManifestPath = getCachedPluginManifestPath(pluginManifestUrlString);
-        Path cacheDir = getCachedPluginsBaseDirectory();
-        Files.createDirectories(cacheDir);
-        Files.writeString(cachedPluginManifestPath, manifestContent);
+        Path cachedPluginManifestPath = getCachedPluginManifestPath(pluginManifestUrlString);
+        Path cacheDir = getCachedPluginsBaseDirectory();
+        Files.createDirectories(cacheDir);
+        Path tmp = Files.createTempFile(cacheDir, ".manifest-", ".tmp");
+        try {
+            Files.writeString(tmp, manifestContent);
+            Files.move(tmp, cachedPluginManifestPath,
+                    StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING);
+        } catch (IOException e) {
+            Files.deleteIfExists(tmp);
+            throw e;
+        }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bbb-common-web/src/main/java/org/bigbluebutton/api/util/PluginUtils.java`
around lines 227 - 235, The savePluginManifestContentInCache method currently
writes in-place and can leave truncated files on crash; change it to write to a
sibling temporary file (e.g., cachedPluginManifestPath + ".tmp"), create the
cacheDir with getCachedPluginsBaseDirectory(), write manifestContent to the temp
file, then atomically replace the target using Files.move(tempPath,
cachedPluginManifestPath, StandardCopyOption.ATOMIC_MOVE,
StandardCopyOption.REPLACE_EXISTING); catch AtomicMoveNotSupportedException and
fall back to Files.move(tempPath, cachedPluginManifestPath,
StandardCopyOption.REPLACE_EXISTING) to maintain correctness across filesystems
and avoid torn writes.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@bbb-common-web/src/main/java/org/bigbluebutton/api/util/PluginUtils.java`:
- Line 52: Change the nullable Boolean field pluginManifestCacheEnabled in
PluginUtils to a primitive boolean with a safe default (e.g., false) so
auto-unboxing cannot NPE; update the field declaration from Boolean to boolean
and ensure any Spring property binding uses a default value or `@Value` fallback,
and remove/adjust any explicit null checks around pluginManifestCacheEnabled
used in the if conditions in PluginUtils (the expressions referenced where
pluginManifestCacheEnabled is read should now rely on the primitive boolean).
- Around line 217-225: The method getPluginManifestContentFromCache logs "Cache
for plugin [{}] not found." on a cache miss and the caller (the method that
invokes getPluginManifestContentFromCache and later logs "Cache not found for
plugin [{}].") duplicates the same message; remove the duplicate by deleting or
suppressing the caller's log so only getPluginManifestContentFromCache emits the
cache-miss message. Search for the exact strings "Cache for plugin [{}] not
found." and "Cache not found for plugin [{}]." and remove the latter from the
caller (or comment it out) so only the callee
(getPluginManifestContentFromCache) logs the miss.
- Around line 55-58: PLUGIN_LOCKS grows unbounded because getLockFor uses the
full substituted pluginUrl as the key; change getLockFor to derive and use a
stable, meeting-independent cache key (e.g., compute an MD5 of a normalized URL
or the manifest file name by replacing/stripping %%MEETING_ID%% or other
volatile segments) and call PLUGIN_LOCKS.computeIfAbsent with that stableKey
instead of the raw pluginUrl; update any callers (e.g., code in
getRawPluginManifestContent and anywhere replaceAllPlaceholdersInManifestUrls is
used) to pass the original URL but let getLockFor compute the normalized key so
locks are reused across meetings and the map no longer grows unbounded.
- Line 49: The field cachedPluginsBaseDirectory in class PluginUtils is publicly
mutable; change its visibility to private to enforce encapsulation, rely on the
existing setter setCachedPluginsBaseDirectory to mutate it, and update any
places that reference PluginUtils.cachedPluginsBaseDirectory directly to call
the setter or a new getter on PluginUtils instead so Spring-wired configuration
and controlled access are preserved.
- Around line 270-272: The boolean check for isRawPluginManifestContentValid can
NPE because getPluginName(pluginManifestContent) may return null; update the
check to safely handle null by calling getPluginName once into a local variable
(e.g., String pluginName = getPluginName(pluginManifestContent)) and then use
pluginName != null && !pluginName.isEmpty() (or change getPluginName to return
"" instead of null) so isRawPluginManifestContentValid uses
isPluginManifestChecksumValid(pluginManifestContent, pluginManifestChecksum) &&
pluginName != null && !pluginName.isEmpty(); ensure you reference getPluginName
and isPluginManifestChecksumValid when applying the fix.

---

Nitpick comments:
In `@bbb-common-web/src/main/java/org/bigbluebutton/api/util/PluginUtils.java`:
- Around line 227-235: The savePluginManifestContentInCache method currently
writes in-place and can leave truncated files on crash; change it to write to a
sibling temporary file (e.g., cachedPluginManifestPath + ".tmp"), create the
cacheDir with getCachedPluginsBaseDirectory(), write manifestContent to the temp
file, then atomically replace the target using Files.move(tempPath,
cachedPluginManifestPath, StandardCopyOption.ATOMIC_MOVE,
StandardCopyOption.REPLACE_EXISTING); catch AtomicMoveNotSupportedException and
fall back to Files.move(tempPath, cachedPluginManifestPath,
StandardCopyOption.REPLACE_EXISTING) to maintain correctness across filesystems
and avoid torn writes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 3f424736-9ee4-448a-b50a-3d8f4777074e

📥 Commits

Reviewing files that changed from the base of the PR and between 05545fd and f0e32fb.

📒 Files selected for processing (2)
  • bbb-common-web/src/main/java/org/bigbluebutton/api/MeetingService.java
  • bbb-common-web/src/main/java/org/bigbluebutton/api/util/PluginUtils.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • bbb-common-web/src/main/java/org/bigbluebutton/api/MeetingService.java

@antobinary antobinary modified the milestones: Release 4.0, Release 3.0 Apr 27, 2026
@github-actions

Copy link
Copy Markdown

This pull request has conflicts ☹
Please resolve those so we can review the pull request.
Thanks.

@gustavotrott

Copy link
Copy Markdown
Contributor

Closes #24997 (via e9cdb17)

@gustavotrott
gustavotrott requested a review from paultrudel April 29, 2026 19:18

@paultrudel paultrudel left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Since the resolved URL with placeholders removed is used as the cache key, is it not the case that any plugin URL with a %%MEETING_ID%% placeholder will always result in a cache miss? Since the substituted meeting ID will be unique per meeting resulting in a unique plugin URL. Would it make sense to just skip caching URLs with meeting ID placeholders?

@gustavotrott

Copy link
Copy Markdown
Contributor

Since the resolved URL with placeholders removed is used as the cache key, is it not the case that any plugin URL with a %%MEETING_ID%% placeholder will always result in a cache miss? Since the substituted meeting ID will be unique per meeting resulting in a unique plugin URL. Would it make sense to just skip caching URLs with meeting ID placeholders?

Agreed and applied. Thanks for the suggestion.

@sonarqubecloud

sonarqubecloud Bot commented May 8, 2026

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

✅ Automated tests have passed!

@gustavotrott
gustavotrott requested a review from paultrudel May 11, 2026 12:03
@antobinary
antobinary merged commit c8a3272 into bigbluebutton:v3.0.x-develop May 11, 2026
58 of 59 checks passed
@TiagoJacobs

Copy link
Copy Markdown
Member

Hello @gustavotrott

I'd suggest renaming "cache" to "mirror" here.

A cache is passive: it refreshes through access (miss → fetch → store), never on its own. This PR does the opposite: persistent local copy with a scheduled cron.daily wipe forcing re-download regardless of access. That's an on-demand mirror with periodic sync, not a cache.

The name matters because pluginManifestCacheEnabled will lead operators to expect cache semantics (per-entry TTL, conditional revalidation, etc.) and debug accordingly when manifests go stale.

Suggested rename:

  • pluginManifestCacheEnabled → pluginManifestMirrorEnabled
  • /var/bigbluebutton/plugin-manifests-cache → .../plugin-manifests-mirror
  • Log: "Found cache for plugin ..." → "Found mirrored manifest for plugin ..."

Easier to fix now than after the flag ships.

Since it's already merged, worth a follow-up PR for the rename.

@antobinary antobinary mentioned this pull request May 11, 2026
12 of 17 tasks
@gustavotrott

Copy link
Copy Markdown
Contributor

Hello @gustavotrott

I'd suggest renaming "cache" to "mirror" here.

A cache is passive: it refreshes through access (miss → fetch → store), never on its own. This PR does the opposite: persistent local copy with a scheduled cron.daily wipe forcing re-download regardless of access. That's an on-demand mirror with periodic sync, not a cache.

The name matters because pluginManifestCacheEnabled will lead operators to expect cache semantics (per-entry TTL, conditional revalidation, etc.) and debug accordingly when manifests go stale.

Suggested rename:

  • pluginManifestCacheEnabled → pluginManifestMirrorEnabled
  • /var/bigbluebutton/plugin-manifests-cache → .../plugin-manifests-mirror
  • Log: "Found cache for plugin ..." → "Found mirrored manifest for plugin ..."

Easier to fix now than after the flag ships.

Since it's already merged, worth a follow-up PR for the rename.

I understand the concern, but I do not think a cache is necessarily passive or access-triggered.

Mirror is not necessarily wrong, but it changes the perception: it suggests a more persistent synchronized replica, usually for availability/distribution, while this feature is mainly about improving meeting creation performance by avoiding repeated remote fetches, which still feels closer to cache semantics to me.

There are cache systems where refresh is proactive and schedule-driven.

For example, IBM BigMemory Max / Ehcache has a "Scheduled Refresh Ahead" strategy, where refresh-ahead operations can run on a regular schedule using Quartz jobs and a cron expression:

https://www.ibm.com/docs/en/webmethods-integration/bigmemory-max/4.4.1?topic=ahead-scheduled-refresh

Their docs describe this as useful when all or a large portion of a cache's data must be updated regularly.

Another example is Sybase/SAP Unwired Server's "Scheduled Cache Refreshes", which describes a schedule-driven cache refresh as a background task that runs at scheduled intervals during normal server operation:

https://infocenter.sybase.com/help/topic/com.sybase.infocenter.dc01092.0213/doc/html/asc1229701049114.html

So I do not think the scheduled update makes this stop being a cache. It is still a local cached copy of the plugin manifests, used to avoid repeated remote fetches during meeting creation. The daily update is only the refresh strategy used to keep the cached manifests fresh.

To me, mirror suggests a stronger replication/synchronization concept, like maintaining a local replica of an upstream source.
This feature is more limited: it stores plugin manifests locally and reuses them for performance/reliability.

Because of that, I still think pluginManifestCacheEnabled and /var/bigbluebutton/plugin-manifests-cache are valid and easier to understand for operators.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cache plugin manifests to improve meeting creation speed

5 participants