Skip to content

fix(bbb-web): respond to /create before downloading pre-uploaded presentations - #24931

Merged
prlanzarin merged 1 commit into
bigbluebutton:v4.0.x-releasefrom
germanocaumo:fix-create-download
Apr 22, 2026
Merged

prlanzarin merged 1 commit into
bigbluebutton:v4.0.x-releasefrom
germanocaumo:fix-create-download

Conversation

@germanocaumo

Copy link
Copy Markdown
Contributor

What does this PR do?

Previously, uploadDocuments() was called before respondWithConference() inside the /create handler. When the request includes a pre-uploaded presentation URL (the common case for Moodle and LTI integrations), uploadDocuments() synchronously downloads the file via PresentationUrlDownloadService.savePresentation() before returning. This download blocks the HTTP thread, delaying the XML response to the LMS by however long the download takes.

The fix swaps the call order: respondWithConference() is called first, then uploadDocuments() continues on the same thread. The meeting is already fully created and running at this point (createMeeting() has returned successfully), so the LMS receives a valid SUCCESS response immediately.

This does not break error handling because:

  • The return value of uploadDocuments() was already ignored at the call site before this change.
  • respondWithConference() always responds with SUCCESS (null msgKey/msg); upload failures are never surfaced to the LMS HTTP response — they are communicated only as internal events to meeting room clients.
  • The only invalid() call inside downloadAndProcessDocument() is inside a catch (UnsupportedEncodingException) block for URLDecoder.decode(..., "UTF-8"), which is unreachable on any JVM since UTF-8 is always available.

After this change, the /create API response time is determined solely by meeting creation and plugin manifest fetching, regardless of the size or download speed of the pre-uploaded presentation.

Motivation

We saw high create times in production where the cullprit was the slow download of the presentation in the create call, taking up to 15+ seconds to return the create result.

How to test

  • Make a create call with a presentation that is slow to download

Before the fix: the create returned only after the download is finished
After the fix: the create returns before trying to download.

…entations

Previously, `uploadDocuments()` was called before `respondWithConference()`
inside the `/create` handler. When the request includes a pre-uploaded
presentation URL (the common case for Moodle and LTI integrations),
`uploadDocuments()` synchronously downloads the file via
`PresentationUrlDownloadService.savePresentation()` before returning.
This download blocks the HTTP thread, delaying the XML response to the LMS
by however long the download takes.

The fix swaps the call order: `respondWithConference()` is called first,
then `uploadDocuments()` continues on the same thread. The meeting is
already fully created and running at this point (createMeeting() has
returned successfully), so the LMS receives a valid SUCCESS response
immediately.

This does not break error handling because:
- The return value of `uploadDocuments()` was already ignored at the call
  site before this change.
- `respondWithConference()` always responds with SUCCESS (null msgKey/msg);
  upload failures are never surfaced to the LMS HTTP response — they are
  communicated only as internal events to meeting room clients.
- The only `invalid()` call inside `downloadAndProcessDocument()` is inside
  a `catch (UnsupportedEncodingException)` block for `URLDecoder.decode(...,
  "UTF-8")`, which is unreachable on any JVM since UTF-8 is always
  available.

After this change, the `/create` API response time is determined solely by
meeting creation and plugin manifest fetching, regardless
of the size or download speed of the pre-uploaded presentation.
@germanocaumo
germanocaumo requested a review from prlanzarin April 16, 2026 21:23
@prlanzarin prlanzarin added this to the Release 4.0 milestone Apr 16, 2026
@coderabbitai

coderabbitai Bot commented Apr 16, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

The create API flow in ApiController has been modified to reorder the execution sequence of two operations. When meetingService.createMeeting(newMeeting) completes successfully, the controller now invokes respondWithConference(newMeeting, null, null) to send the conference response before calling uploadDocuments(xmlModules, newMeeting, false). Previously, document uploads were processed before the response was sent to the client.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: responding to the /create API before downloading presentations, which directly matches the primary modification in the changeset.
Description check ✅ Passed The description is clearly related to the changeset, explaining the motivation, technical details, and testing approach for reordering respondWithConference() and uploadDocuments() calls.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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.

@sonarqubecloud

Copy link
Copy Markdown

@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

🧹 Nitpick comments (1)
bigbluebutton-web/grails-app/controllers/org/bigbluebutton/web/controllers/ApiController.groovy (1)

1740-1747: Dead/broken error path in downloadAndProcessDocument after the reorder.

With the new call order, the invalid("fileNameError", ...) branch here executes after respondWithConference has already committed the response for the /create call (when invoked via the create flow). Grails' render would then throw IllegalStateException: response already committed instead of producing the intended error XML.

The PR description correctly notes this branch is practically unreachable because UTF-8 is mandated by the JVM spec, so this is not a real runtime bug. But since the invalid(...) call here is now effectively dead for the create path (and still valid for insertDocument), consider either removing it or replacing it with a plain log + early return so future refactors don't resurrect a broken double-render. The insertDocument caller already tolerates a silent failure (it checks the boolean return value).

Suggested simplification
     if (StringUtils.isEmpty(fileName)) {
       try {
         presOrigFilename = URLDecoder.decode(address.tokenize("/")[-1], "UTF-8");
       } catch (UnsupportedEncodingException e) {
-        log.error "Couldn't decode the uploaded file name.", e
-        invalid("fileNameError", "Cannot decode the uploaded file name")
-        return;
+        // UTF-8 is guaranteed by the JVM; treat as unrecoverable and skip this document.
+        log.error("Couldn't decode the uploaded file name for address=[${address}]", e)
+        return
       }
     } else {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@bigbluebutton-web/grails-app/controllers/org/bigbluebutton/web/controllers/ApiController.groovy`
around lines 1740 - 1747, The dead/broken error path in
downloadAndProcessDocument occurs because invalid("fileNameError", ...) can run
after respondWithConference has already committed the response (causing
IllegalStateException); change the branch that catches
UnsupportedEncodingException inside downloadAndProcessDocument to avoid calling
invalid and instead log the decoding failure and return false (or just return)
so the create flow isn't double-rendered; keep the behavior that insertDocument
can tolerate a silent failure, and reference downloadAndProcessDocument,
invalid(...), respondWithConference and insertDocument to locate and modify the
code.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@bigbluebutton-web/grails-app/controllers/org/bigbluebutton/web/controllers/ApiController.groovy`:
- Around line 218-221: The post-response call to uploadDocuments (triggered
after respondWithConference) still runs synchronously on the request thread and
can block the servlet worker during
presDownloadService.savePresentation/downloadAndProcessDocument; change the flow
to dispatch uploadDocuments(newMeeting, xmlModules, false) to a background
executor/task so it runs asynchronously after respondWithConference returns (use
an injected TaskExecutor/ExecutorService or Grails async mechanism), and ensure
the asynchronous task catches and logs all exceptions from
presDownloadService.savePresentation/downloadAndProcessDocument so failures are
visible to operators.

---

Nitpick comments:
In
`@bigbluebutton-web/grails-app/controllers/org/bigbluebutton/web/controllers/ApiController.groovy`:
- Around line 1740-1747: The dead/broken error path in
downloadAndProcessDocument occurs because invalid("fileNameError", ...) can run
after respondWithConference has already committed the response (causing
IllegalStateException); change the branch that catches
UnsupportedEncodingException inside downloadAndProcessDocument to avoid calling
invalid and instead log the decoding failure and return false (or just return)
so the create flow isn't double-rendered; keep the behavior that insertDocument
can tolerate a silent failure, and reference downloadAndProcessDocument,
invalid(...), respondWithConference and insertDocument to locate and modify the
code.
🪄 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: feb1a00e-ceb3-4844-a0ce-d2475ed2c989

📥 Commits

Reviewing files that changed from the base of the PR and between ab2a686 and 68e21d6.

📒 Files selected for processing (1)
  • bigbluebutton-web/grails-app/controllers/org/bigbluebutton/web/controllers/ApiController.groovy

Comment on lines 218 to 221
if (meetingService.createMeeting(newMeeting)) {
respondWithConference(newMeeting, null, null)
// See if the request came with pre-uploading of presentation.
uploadDocuments(xmlModules, newMeeting, false); //

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.

⚠️ Potential issue | 🟡 Minor

Reorder looks correct; worker thread still blocked until uploads finish.

Sending respondWithConference before uploadDocuments correctly fixes the client-visible latency described in the PR. A couple of things to be aware of post-change:

  1. uploadDocuments(...) still runs synchronously on the request-handling thread after render(...) inside respondWithConference. The client sees the response promptly, but the servlet container's worker thread remains tied up for the duration of each presDownloadService.savePresentation(...) call (see downloadAndProcessDocument at Line 1773). Under bursts of /create calls that reference large or slow URLs, this can still exhaust the HTTP thread pool even though callers no longer wait. Consider dispatching the post-response upload work to an executor / background task as a follow-up.
  2. Any exception thrown by uploadDocuments after the response has been committed will be swallowed by Grails (or logged as a stack trace) and the client will have already received SUCCESS. That matches the PR's stated intent, but worth double-checking that uploadDocuments logs failures loudly enough for operators to notice, since callers can no longer infer problems from the HTTP status.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@bigbluebutton-web/grails-app/controllers/org/bigbluebutton/web/controllers/ApiController.groovy`
around lines 218 - 221, The post-response call to uploadDocuments (triggered
after respondWithConference) still runs synchronously on the request thread and
can block the servlet worker during
presDownloadService.savePresentation/downloadAndProcessDocument; change the flow
to dispatch uploadDocuments(newMeeting, xmlModules, false) to a background
executor/task so it runs asynchronously after respondWithConference returns (use
an injected TaskExecutor/ExecutorService or Grails async mechanism), and ensure
the asynchronous task catches and logs all exceptions from
presDownloadService.savePresentation/downloadAndProcessDocument so failures are
visible to operators.

@github-actions

Copy link
Copy Markdown

✅ Automated tests have passed!

@prlanzarin

Copy link
Copy Markdown
Member

cc @paultrudel please assign yourself as a reviewer as well if this is of your interest and applicable.

@antobinary
antobinary requested a review from paultrudel April 17, 2026 09:55
@antobinary

Copy link
Copy Markdown
Member

The code on BBB 3.0 looks identical (to the 'before' state), so this is a candidate for backporting if/when all necessary testing+reviewing is complete.

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.

4 participants