Skip to content

Commit

Permalink
Merge pull request #263 from trivalik/forwardSecurityError
Browse files Browse the repository at this point in the history
forward internal errors instead of timeout status codes
  • Loading branch information
awcullen authored Dec 10, 2023
2 parents 4c04b30 + 2478e57 commit 6595ddc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion UaClient/ServiceModel/Ua/Channels/ClientSecureChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,13 @@ public virtual async Task<IServiceResponse> RequestAsync(IServiceRequest request
// TimestampHeader takes care that the RequestHeader property will not be null
using (var timeoutCts = new CancellationTokenSource((int)request.RequestHeader!.TimeoutHint))
using (var linkedCts = CancellationTokenSource.CreateLinkedTokenSource(timeoutCts.Token, _channelCts.Token, token))
using (var registration = linkedCts.Token.Register(o => ((ServiceOperation)o!).TrySetException(new ServiceResultException(StatusCodes.BadRequestTimeout)), operation, false))
using (var registration = linkedCts.Token.Register(o =>
{
var statusCode = StatusCodes.BadRequestTimeout;
if (PeakFirstPendingException() is ServiceResultException result)
statusCode = result.StatusCode;
((ServiceOperation)o!).TrySetException(new ServiceResultException(statusCode));
}, operation, false))
{
if (_pendingRequests.Post(operation))
{
Expand Down
10 changes: 10 additions & 0 deletions UaClient/ServiceModel/Ua/Channels/CommunicationObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,16 @@ protected void AddPendingException(Exception exception)
_exceptions.Value.Enqueue(exception);
}

protected Exception? PeakFirstPendingException()
{
if (_exceptions.Value.TryPeek(out var ex))
{
return ex;
}

return null;
}

protected Exception? GetPendingException()
{
if (_exceptions.Value.TryDequeue(out var ex))
Expand Down

0 comments on commit 6595ddc

Please sign in to comment.