Skip to content

Commit 0bd4ae5

Browse files
committed
Flatten the credential dispatch hot path
Verified strict Debug cluster build, scoped formatting, governance, one real HTTP SDK and MCP authentication case, and matched allocation call trees under single-silo document GET.
1 parent 44cf3c9 commit 0bd4ae5

1 file changed

Lines changed: 27 additions & 23 deletions

File tree

‎src/KeyLoad/ClientApi/Execution/CanonicalCredentialDispatch.cs‎

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,35 @@ internal static async Task<PrincipalRecord> AuthenticateSubjectAsync(OrleansNode
1818
var grains = node.DatabaseReady ? node.Grains!
1919
: throw Errors.Fail(ErrorCode.OwnershipLost, OrleansNodeProtocol.RoutingUnavailable);
2020
var user = grains.GetGrain<IUserGrain>(UserGrainIdentity.For(AuthorizationIdentity.ReadCredentialId(credential)));
21-
PrincipalRecord? result = null;
22-
var failures = new List<Exception>();
23-
await ServerFailureObserver.ObserveAsync(async () =>
21+
var identity = node.OpenRequestContext(null, requestId, Guid.Empty, connection.Token, connection.Id);
22+
PrincipalRecord result;
23+
try
2424
{
25-
using var identity = node.OpenRequestContext(null, requestId, Guid.Empty, connection.Token, connection.Id);
26-
await ServerFailureObserver.ObserveAsync(async () =>
25+
onStarted?.Invoke();
26+
try
2727
{
28-
onStarted?.Invoke();
29-
try
30-
{
31-
var verified = await user.AuthenticateAsync(credential, connection.Token);
32-
result = new(verified.Id, verified.TenantId, [], []);
33-
}
34-
catch (Exception failure) when (failure is OrleansException or TimeoutException
35-
&& CqrsBoundaryErrors.IsNonFatal(failure))
36-
{
37-
throw OrleansRpcFailure.Translate(failure, false, requestId,
38-
node.RuntimeServices.GetRequiredService<ILogger<OrleansNode>>(),
39-
OrleansRpcFailureStage.Consumption,
40-
new(Guid.Empty, GrainReadKind.Authenticate, null), connection.Token);
41-
}
42-
}, failures);
43-
}, failures);
44-
ServerFailureObserver.ThrowIfAny(failures);
45-
return result ?? throw Errors.Fail(ErrorCode.Corruption, PostgresProtocol.Invalid);
28+
var verified = await user.AuthenticateAsync(credential, connection.Token);
29+
result = new(verified.Id, verified.TenantId, [], []);
30+
}
31+
catch (Exception failure) when (failure is OrleansException or TimeoutException
32+
&& CqrsBoundaryErrors.IsNonFatal(failure))
33+
{
34+
throw OrleansRpcFailure.Translate(failure, false, requestId,
35+
node.RuntimeServices.GetRequiredService<ILogger<OrleansNode>>(),
36+
OrleansRpcFailureStage.Consumption,
37+
new(Guid.Empty, GrainReadKind.Authenticate, null), connection.Token);
38+
}
39+
}
40+
catch (Exception failure)
41+
{
42+
if (RequestWorkSettlement.Observe(identity.Dispose).Value is { } cleanup)
43+
{
44+
throw new AggregateException(failure, cleanup);
45+
}
46+
throw;
47+
}
48+
identity.Dispose();
49+
return result;
4650
}
4751

4852
private static async Task<PrincipalRecord> ReadCurrentPrincipalAsync(OrleansNode node,

0 commit comments

Comments
 (0)