Skip to content

RE1-T117 Bug fixes#408

Merged
ucswift merged 2 commits into
masterfrom
develop
Jun 11, 2026
Merged

RE1-T117 Bug fixes#408
ucswift merged 2 commits into
masterfrom
develop

Conversation

@ucswift

@ucswift ucswift commented Jun 11, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Bug Fixes

    • Fixed audit log queries to normalize requested date ranges and avoid SQL Server datetime overflow.
    • Improved RabbitMQ connection and channel cleanup to prevent leaked channels and connection resets.
    • Corrected username normalization to handle legacy accounts reliably.
  • Chores

    • Updated database parameter binding and async cleanup patterns for greater reliability.

@request-info

request-info Bot commented Jun 11, 2026

Copy link
Copy Markdown

Thanks for opening this, but we'd appreciate a little more information. Could you update it with more details?

@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 04700712-7c04-4157-a799-e870029da6a3

📥 Commits

Reviewing files that changed from the base of the PR and between eeb0ebf and 2288bd6.

📒 Files selected for processing (1)
  • Providers/Resgrid.Providers.Bus.Rabbit/RabbitConnection.cs
🚧 Files skipped from review as they are similar to previous changes (1)
  • Providers/Resgrid.Providers.Bus.Rabbit/RabbitConnection.cs

📝 Walkthrough

Walkthrough

This PR normalizes audit query datetimes and binds them as DateTime2, switches RabbitMQ channels/connections to async disposal with proper reset handling, and corrects getting/setting normalized usernames in the identity store.

Changes

Infrastructure safety and resource cleanup fixes

Layer / File(s) Summary
Audit query datetime normalization and parameter safety
Core/Resgrid.Services/AuditService.cs, Repositories/Resgrid.Repositories.DataRepository/AuditLogsRepository.cs
AuditService clamps startDate to SqlDateTime.MinValue and defaults endDate to DateTime.UtcNow before querying; AuditLogsRepository binds StartDate/EndDate as DbType.DateTime2 to prevent SQL Server overflow errors when querying audit logs with out-of-range datetime values.
RabbitMQ async channel and connection disposal
Providers/Resgrid.Providers.Bus.Rabbit/RabbitConnection.cs, Providers/Resgrid.Providers.Bus.Rabbit/RabbitInboundQueueProvider.cs, Providers/Resgrid.Providers.Bus.Rabbit/RabbitOutboundQueueProvider.cs, Providers/Resgrid.Providers.Bus.Rabbit/RabbitTopicProvider.cs
RabbitMQ connection and channel creation sites switch from synchronous using/Dispose() to await using/DisposeAsync() across providers, and stale/non-open connections are disposed/reset with ConnectionReset raised to re-run client verification.
Identity user store normalized username handling
Repositories/Resgrid.Repositories.DataRepository/Stores/IdentityUserStore.cs
GetNormalizedUserNameAsync prefers NormalizedUserName with fallback to uppercase UserName for legacy rows; SetNormalizedUserNameAsync now assigns the normalized value to NormalizedUserName instead of Email.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant AuditService
  participant AuditLogsRepository
  participant SQLDatabase
  Caller->>AuditService: GetAuditLogsForDepartmentPagedAsync(startDate,endDate)
  AuditService->>AuditService: Compute safeStart (clamp to SqlDateTime.MinValue) and safeEnd (default DateTime.UtcNow)
  AuditService->>AuditLogsRepository: GetAuditLogsForDepartmentPagedAsync(safeStart,safeEnd,(int?)logType)
  AuditLogsRepository->>AuditLogsRepository: Bind params as DbType.DateTime2
  AuditLogsRepository->>SQLDatabase: Execute typed-parameter query
  SQLDatabase-->>AuditLogsRepository: Return rows
  AuditLogsRepository-->>AuditService: Return paged results
  AuditService-->>Caller: Return audit logs
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • Resgrid/Core#322: Modifies RabbitMQ lifecycle behavior in RabbitConnection and RabbitTopicProvider alongside connection reset and early-return optimizations.
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

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.
Title check ❓ Inconclusive The title references a ticket (RE1-T117) and broadly states "Bug fixes" but does not convey the specific nature or scope of the changes made across six files and multiple components. Consider using a more descriptive title that highlights the primary fix, such as 'Fix async channel disposal in RabbitMQ providers and audit log datetime handling' to better summarize the changeset.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
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 develop

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: 1

Caution

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

⚠️ Outside diff range comments (1)
Providers/Resgrid.Providers.Bus.Rabbit/RabbitConnection.cs (1)

69-77: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Remove the duplicate semaphore release in the fallback path.

When the first connection attempt fails and RabbitHostname2 is configured, _semaphore.Release() runs in both the inner finally (Line 71) and outer finally (Line 77). That over-releases SemaphoreSlim(1,1) and can throw SemaphoreFullException, masking the original connection failure.

Suggested fix
-						finally
-						{
-							_semaphore.Release();
-						}
+						finally
+						{
+							// outer finally releases the semaphore
+						}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Providers/Resgrid.Providers.Bus.Rabbit/RabbitConnection.cs` around lines 69 -
77, The code double-releases the SemaphoreSlim when the first connection attempt
fails and RabbitHostname2 is used (both the inner finally and the outer finally
call _semaphore.Release()), causing SemaphoreFullException; fix by ensuring
Release is called exactly once per Acquire — either remove the duplicate outer
_semaphore.Release() in the fallback path or introduce a local bool (e.g.,
lockTaken) set when entering the semaphore and only call _semaphore.Release() in
the finally if lockTaken is true; update the connection logic around the
RabbitHostname2 fallback so each semaphore Wait/Acquire is paired with a single
guarded Release.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@Providers/Resgrid.Providers.Bus.Rabbit/RabbitConnection.cs`:
- Line 185: The check if (!_connection.IsOpen) can throw NullReferenceException
when VerifyAndCreateClients(clientName) failed and _connection is null; update
the guard to first ensure _connection is not null before accessing IsOpen (e.g.,
check _connection != null && _connection.IsOpen or invert to _connection == null
|| !_connection.IsOpen), inside the RabbitConnection class method that calls
VerifyAndCreateClients(clientName) so the code safely handles a null _connection
and proceeds to create/recreate the connection only when needed.

---

Outside diff comments:
In `@Providers/Resgrid.Providers.Bus.Rabbit/RabbitConnection.cs`:
- Around line 69-77: The code double-releases the SemaphoreSlim when the first
connection attempt fails and RabbitHostname2 is used (both the inner finally and
the outer finally call _semaphore.Release()), causing SemaphoreFullException;
fix by ensuring Release is called exactly once per Acquire — either remove the
duplicate outer _semaphore.Release() in the fallback path or introduce a local
bool (e.g., lockTaken) set when entering the semaphore and only call
_semaphore.Release() in the finally if lockTaken is true; update the connection
logic around the RabbitHostname2 fallback so each semaphore Wait/Acquire is
paired with a single guarded Release.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b80b401c-daf1-471e-8473-2b7b8519254b

📥 Commits

Reviewing files that changed from the base of the PR and between 674eae9 and eeb0ebf.

📒 Files selected for processing (7)
  • Core/Resgrid.Services/AuditService.cs
  • Providers/Resgrid.Providers.Bus.Rabbit/RabbitConnection.cs
  • Providers/Resgrid.Providers.Bus.Rabbit/RabbitInboundQueueProvider.cs
  • Providers/Resgrid.Providers.Bus.Rabbit/RabbitOutboundQueueProvider.cs
  • Providers/Resgrid.Providers.Bus.Rabbit/RabbitTopicProvider.cs
  • Repositories/Resgrid.Repositories.DataRepository/AuditLogsRepository.cs
  • Repositories/Resgrid.Repositories.DataRepository/Stores/IdentityUserStore.cs

Comment thread Providers/Resgrid.Providers.Bus.Rabbit/RabbitConnection.cs Outdated
@ucswift

ucswift commented Jun 11, 2026

Copy link
Copy Markdown
Member Author

Approve

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This PR is approved.

@ucswift ucswift merged commit 2b8c5f9 into master Jun 11, 2026
17 of 19 checks passed
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.

1 participant