Skip to content

fix: release Biorender semaphore permit on invalid email#209

Open
rlorenzo wants to merge 1 commit into
mainfrom
fix/biorender-semaphore-leak
Open

fix: release Biorender semaphore permit on invalid email#209
rlorenzo wants to merge 1 commit into
mainfrom
fix/biorender-semaphore-leak

Conversation

@rlorenzo
Copy link
Copy Markdown
Contributor

Summary

BiorenderStudentLookup.GetBiorenderStudentInfo acquires a semaphore permit via throttler.WaitAsync() before checking IsValidEmail, but Release() only runs inside the scheduled Task.Run. Each invalid email permanently consumes a permit, so 20 invalid entries in a row deadlock the loop at WaitAsync() waiting for permits that will never be returned.

Fix

Reorder: trim and validate first, continue on invalid, then WaitAsync only when work is actually being scheduled.

Context

Split from #192 (CodeQL dispose hygiene). CodeRabbit surfaced this during the #192 review, but it is a control-flow correction rather than a dispose annotation, so it lives here for cleaner git log/bisect.

Independent of #192 — either can merge first. Touches adjacent lines on var throttler = new SemaphoreSlim(...) so a trivial merge resolution may be needed for whichever lands second (keep the using from #192, keep the reorder from here).

Test plan

  • npm run test:backend — 1946 tests passing
  • npm run lint web/Areas/Computing/Services/BiorenderStudentLookup.cs — clean
  • npm run verify:build — clean
  • Manual: call GetBiorenderStudentInfo with >20 invalid emails, confirm it returns (currently hangs)

GetBiorenderStudentInfo called throttler.WaitAsync before checking
IsValidEmail, but Release only ran inside the scheduled task. Each
invalid email consumed a permit permanently, so 20 invalid entries in
a row would deadlock the loop on WaitAsync.

Move trim/validation ahead of WaitAsync and `continue` on invalid so
permits are only acquired when work is actually scheduled.

Caught in CodeRabbit review of #192. Split from #192 because this is
a control-flow correction, not a dispose-hygiene change.
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 21, 2026

Codecov Report

❌ Patch coverage is 0% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 43.02%. Comparing base (d28d37c) to head (f67f12c).

Files with missing lines Patch % Lines
...Areas/Computing/Services/BiorenderStudentLookup.cs 0.00% 16 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #209   +/-   ##
=======================================
  Coverage   43.02%   43.02%           
=======================================
  Files         881      881           
  Lines       51437    51437           
  Branches     4812     4812           
=======================================
  Hits        22131    22131           
  Misses      28780    28780           
  Partials      526      526           
Flag Coverage Δ
backend 43.10% <0.00%> (ø)
frontend 41.47% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@codecov-commenter
Copy link
Copy Markdown

Bundle Report

Bundle size has no change ✅

@rlorenzo
Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 22, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 22, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: fc518d2b-d1c4-4dd3-91e4-45531c6faa68

📥 Commits

Reviewing files that changed from the base of the PR and between d28d37c and f67f12c.

📒 Files selected for processing (1)
  • web/Areas/Computing/Services/BiorenderStudentLookup.cs

📝 Walkthrough

Walkthrough

GetBiorenderStudentInfo refactors its email processing loop to validate and normalize emails before acquiring semaphore permits. Invalid addresses are skipped early via continue, preventing wasted resource allocation on malformed input.

Changes

Email Validation and Semaphore Optimization

Layer / File(s) Summary
Email normalization and semaphore acquisition reordering
web/Areas/Computing/Services/BiorenderStudentLookup.cs
Each email is trimmed and appended with @ucdavis.edu when missing an @. Invalid emails skip processing entirely via continue before semaphore acquisition. Valid emails acquire the semaphore, execute Task.Run to fetch student data via GetSingleStudent, and release the permit in a finally block, ensuring resource cleanup.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main fix: reordering semaphore logic to release permits on invalid emails instead of leaking them.
Description check ✅ Passed The description is well-related to the changeset, explaining the bug (semaphore permit leak on invalid emails), the fix (reorder validation before WaitAsync), and test results.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/biorender-semaphore-leak

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.

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.

2 participants