Repository navigation
fix(bbb-web): respond to /create before downloading pre-uploaded presentations - #24931
Conversation
…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.
WalkthroughThe Estimated code review effort🎯 2 (Simple) | ⏱️ ~5 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
There was a problem hiding this comment.
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 indownloadAndProcessDocumentafter the reorder.With the new call order, the
invalid("fileNameError", ...)branch here executes afterrespondWithConferencehas already committed the response for the /create call (when invoked via the create flow). Grails'renderwould then throwIllegalStateException: response already committedinstead of producing the intended error XML.The PR description correctly notes this branch is practically unreachable because
UTF-8is mandated by the JVM spec, so this is not a real runtime bug. But since theinvalid(...)call here is now effectively dead for the create path (and still valid forinsertDocument), consider either removing it or replacing it with a plain log + earlyreturnso future refactors don't resurrect a broken double-render. TheinsertDocumentcaller 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
📒 Files selected for processing (1)
bigbluebutton-web/grails-app/controllers/org/bigbluebutton/web/controllers/ApiController.groovy
| if (meetingService.createMeeting(newMeeting)) { | ||
| respondWithConference(newMeeting, null, null) | ||
| // See if the request came with pre-uploading of presentation. | ||
| uploadDocuments(xmlModules, newMeeting, false); // |
There was a problem hiding this comment.
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:
uploadDocuments(...)still runs synchronously on the request-handling thread afterrender(...)insiderespondWithConference. The client sees the response promptly, but the servlet container's worker thread remains tied up for the duration of eachpresDownloadService.savePresentation(...)call (seedownloadAndProcessDocumentat 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.- Any exception thrown by
uploadDocumentsafter the response has been committed will be swallowed by Grails (or logged as a stack trace) and the client will have already receivedSUCCESS. That matches the PR's stated intent, but worth double-checking thatuploadDocumentslogs 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.
✅ Automated tests have passed! |
|
cc @paultrudel please assign yourself as a reviewer as well if this is of your interest and applicable. |
|
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. |



What does this PR do?
Previously,
uploadDocuments()was called beforerespondWithConference()inside the/createhandler. When the request includes a pre-uploaded presentation URL (the common case for Moodle and LTI integrations),uploadDocuments()synchronously downloads the file viaPresentationUrlDownloadService.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, thenuploadDocuments()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:
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.invalid()call insidedownloadAndProcessDocument()is inside acatch (UnsupportedEncodingException)block forURLDecoder.decode(..., "UTF-8"), which is unreachable on any JVM since UTF-8 is always available.After this change, the
/createAPI 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
Before the fix: the create returned only after the download is finished
After the fix: the create returns before trying to download.