Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: [Stage 3] Merge latest APIM Gateway changes #23

Merged
merged 5 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/Dependencies.System2.props
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@

<SystemTextEncodingCodePages2PackageVersion>4.5.0</SystemTextEncodingCodePages2PackageVersion>
<SystemTextJson2PackageVersion>4.7.1</SystemTextJson2PackageVersion>
<SystemTextEncodingsWeb2PackageVersion>4.6.0</SystemTextEncodingsWeb2PackageVersion>
<SystemTextEncodingsWeb2PackageVersion>4.7.2</SystemTextEncodingsWeb2PackageVersion>
<SystemThreadingChannels2PackageVersion>4.5.0</SystemThreadingChannels2PackageVersion>
<SystemThreadingTasksDataflow2PackageVersion>4.9.0</SystemThreadingTasksDataflow2PackageVersion>
<SystemThreadingTasksExtensions2PackageVersion>4.5.3</SystemThreadingTasksExtensions2PackageVersion>
Expand Down
2 changes: 1 addition & 1 deletion build/Dependencies.System3.props
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@

<SystemTextEncodingCodePages3PackageVersion>4.7.1</SystemTextEncodingCodePages3PackageVersion>
<SystemTextJson3PackageVersion>4.7.2</SystemTextJson3PackageVersion>
<SystemTextEncodingsWeb3PackageVersion>4.7.1</SystemTextEncodingsWeb3PackageVersion>
<SystemTextEncodingsWeb3PackageVersion>4.7.2</SystemTextEncodingsWeb3PackageVersion>
<SystemThreadingChannels3PackageVersion>4.7.1</SystemThreadingChannels3PackageVersion>
<SystemThreadingTasksDataflow3PackageVersion>4.11.1</SystemThreadingTasksDataflow3PackageVersion>
<SystemThreadingTasksExtensions3PackageVersion>4.5.4</SystemThreadingTasksExtensions3PackageVersion>
Expand Down
5 changes: 3 additions & 2 deletions src/DotNetty.Handlers/Tls/TlsHandler.Handshake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ namespace DotNetty.Handlers.Tls
partial class TlsHandler
{
private static readonly Action<object, object> s_handshakeCompletionCallback = (t, s) => HandleHandshakeCompleted((Task)t, (TlsHandler)s);
private static readonly TaskCanceledException s_taskCanceledException = new TaskCanceledException();
public static readonly AttributeKey<SslStream> SslStreamAttrKey = AttributeKey<SslStream>.ValueOf("SSLSTREAM");

private bool EnsureAuthenticated(IChannelHandlerContext ctx)
Expand Down Expand Up @@ -212,10 +213,10 @@ private static void HandleHandshakeCompleted(Task task, TlsHandler self)
Debug.Assert(!oldState.HasAny(TlsHandlerState.Authenticated));
self.State = (oldState | TlsHandlerState.FailedAuthentication) & ~TlsHandlerState.Authenticating;
var taskExc = task.Exception;
var cause = taskExc.Unwrap();
var cause = task.IsFaulted ? taskExc.Unwrap() : s_taskCanceledException;
try
{
if (self._handshakePromise.TrySetException(taskExc))
if (task.IsFaulted ? self._handshakePromise.TrySetException(taskExc) : self._handshakePromise.TrySetCanceled())
{
TlsUtils.NotifyHandshakeFailure(capturedContext, cause, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,18 @@ private int ReadFromInput(Memory<byte> destination) // byte[] destination, int d
}

public override void Write(ReadOnlySpan<byte> buffer)
=> _owner.FinishWrap(buffer, _owner._lastContextWritePromise);
=> _owner.FinishWrap(buffer, _owner._lastContextWritePromise ?? _owner.CapturedContext.VoidPromise());

public override void Write(byte[] buffer, int offset, int count)
=> _owner.FinishWrap(buffer, offset, count, _owner._lastContextWritePromise);
=> _owner.FinishWrap(buffer, offset, count, _owner._lastContextWritePromise ?? _owner.CapturedContext.VoidPromise());

public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default)
{
return new ValueTask(_owner.FinishWrapNonAppDataAsync(buffer, _owner.CapturedContext.NewPromise()));
return new ValueTask(_owner.FinishWrapNonAppDataAsync(buffer, _owner._lastContextWritePromise ?? _owner.CapturedContext.NewPromise()));
}

public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
=> _owner.FinishWrapNonAppDataAsync(buffer, offset, count, _owner.CapturedContext.NewPromise());
=> _owner.FinishWrapNonAppDataAsync(buffer, offset, count, _owner._lastContextWritePromise ?? _owner.CapturedContext.NewPromise());
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/DotNetty.Handlers/Tls/TlsHandler.MediationStream.NetFx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ private int ReadFromInput(byte[] destination, int destinationOffset, int destina
return length;
}

public override void Write(byte[] buffer, int offset, int count) => _owner.FinishWrap(buffer, offset, count, _owner._lastContextWritePromise);
public override void Write(byte[] buffer, int offset, int count) => _owner.FinishWrap(buffer, offset, count, _owner._lastContextWritePromise ?? _owner.CapturedContext.VoidPromise());

public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
=> _owner.FinishWrapNonAppDataAsync(buffer, offset, count, _owner.CapturedContext.NewPromise());
=> _owner.FinishWrapNonAppDataAsync(buffer, offset, count, _owner._lastContextWritePromise ?? _owner.CapturedContext.NewPromise());

private static readonly Action<Task, object> s_writeCompleteCallback = (t, s) => HandleChannelWriteComplete(t, s);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ private int ReadFromInput(byte[] destination, int destinationOffset, int destina
return length;
}

public override void Write(byte[] buffer, int offset, int count) => _owner.FinishWrap(buffer, offset, count, _owner._lastContextWritePromise);
public override void Write(byte[] buffer, int offset, int count) => _owner.FinishWrap(buffer, offset, count, _owner._lastContextWritePromise ?? _owner.CapturedContext.NewPromise());

public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
=> _owner.FinishWrapNonAppDataAsync(buffer, offset, count, _owner.CapturedContext.NewPromise());
=> _owner.FinishWrapNonAppDataAsync(buffer, offset, count, _owner._lastContextWritePromise ?? _owner.CapturedContext.NewPromise());
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/DotNetty.Handlers/Tls/TlsHandler.Writer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace DotNetty.Handlers.Tls
using System.Runtime.CompilerServices;
using System.Runtime.ExceptionServices;
using System.Net.Security;
using System.Threading;
using System.Threading.Tasks;
using DotNetty.Buffers;
using DotNetty.Common.Concurrency;
Expand Down Expand Up @@ -257,6 +258,21 @@ private Task FinishWrapNonAppDataAsync(byte[] buffer, int offset, int count, IPr
this.ReadIfNeeded(capturedContext);
return future;
}

#if NETCOREAPP || NETSTANDARD_2_0_GREATER
private static async ValueTask LinkOutcome(ValueTask valueTask, IPromise promise)
{
try
{
await valueTask;
promise.TryComplete();
}
catch (Exception ex)
{
promise.TrySetException(ex);
}
}
#endif

[MethodImpl(MethodImplOptions.NoInlining)]
private static InvalidOperationException NewPendingWritesNullException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,10 @@ public bool IsEmpty()
/// </summary>
public void ReleaseAndFailAll(Exception cause)
{
ReleaseAndCompleteAll(TaskUtil.FromException(cause));
var failedTask = TaskUtil.FromException(cause);
//if _bufAndListenerPairs queue is empty, the task will end up unobserved
failedTask.Ignore();
ReleaseAndCompleteAll(failedTask);
}

/// <summary>
Expand Down
18 changes: 9 additions & 9 deletions test/DotNetty.Handlers.Proxy.Tests/ProxyHandlerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ public static List<object[]> CreateTestItems()

/*
Note: Test keeps failing and Tom/Max agreed to skip it for now
new FailureTestItem(
"HTTP proxy: rejected anonymous connection",
DESTINATION, "status: 401",
new HttpProxyHandler(HttpProxy.Address)),
new FailureTestItem(
"HTTP proxy: rejected anonymous connection",
DESTINATION, "status: 401",
new HttpProxyHandler(HttpProxy.Address)),
*/

new SuccessTestItem(
Expand Down Expand Up @@ -173,11 +173,11 @@ public static List<object[]> CreateTestItems()

/*
Note: Test keeps failing and Tom/Max agreed to skip it for now
new FailureTestItem(
"Anonymous HTTPS proxy: rejected connection",
BAD_DESTINATION, "status: 403",
CreateClientTlsHandler(),
new HttpProxyHandler(AnonHttpsProxy.Address)),
new FailureTestItem(
"Anonymous HTTPS proxy: rejected connection",
BAD_DESTINATION, "status: 403",
CreateClientTlsHandler(),
new HttpProxyHandler(AnonHttpsProxy.Address)),
*/

new FailureTestItem(
Expand Down
Loading