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

Remove System.Net.Connections and related features #41648

Merged
merged 4 commits into from
Sep 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 0 additions & 2 deletions src/libraries/NetCoreAppLibrary.props
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
System.IO.FileSystem.Watcher;
System.IO.IsolatedStorage;
System.IO.MemoryMappedFiles;
System.IO.Pipelines;
Copy link
Member

Choose a reason for hiding this comment

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

Is removing pipelines reference here going to require a reaction in aspnetcore? Did we make changes to not reference it ourselves? @halter73 @Tratcher @JunTaoLuo

System.IO.Pipes;
System.IO.Pipes.AccessControl;
System.IO.UnmanagedMemoryStream;
Expand All @@ -57,7 +56,6 @@
System.Linq.Parallel;
System.Linq.Queryable;
System.Memory;
System.Net.Connections;
System.Net.Http;
System.Net.Http.Json;
System.Net.HttpListener;
Expand Down
21 changes: 21 additions & 0 deletions src/libraries/System.Net.Connections/ref/System.Net.Connections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,24 @@ public SocketsConnectionFactory(System.Net.Sockets.SocketType socketType, System
protected virtual System.Net.Sockets.Socket CreateSocket(System.Net.Sockets.AddressFamily addressFamily, System.Net.Sockets.SocketType socketType, System.Net.Sockets.ProtocolType protocolType, System.Net.EndPoint? endPoint, System.Net.Connections.IConnectionProperties? options) { throw null; }
}
}
namespace System.Net
Copy link
Member

Choose a reason for hiding this comment

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

How does it work if we remove System.Net.Connections from shared framework but still depend on it? Or is it still present? Do we still expose it to the user?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not exposed to the user. It's still part of the tree, but not dropped.

{
public enum NetworkError : int
{
Other = 0,
EndPointInUse,
HostNotFound,
TimedOut,
ConnectionRefused,
OperationAborted,
ConnectionAborted,
ConnectionReset,
}
public class NetworkException : System.IO.IOException
{
public NetworkException(NetworkError error, Exception? innerException = null) { }
public NetworkException(string message, NetworkError error, Exception? innerException = null) { }
protected NetworkException(System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext streamingContext) { }
public NetworkError NetworkError { get { throw null; } }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<ItemGroup>
<Compile Include="$(CommonPath)System\Net\NetworkErrorHelper.cs" Link="Common\System\Net\NetworkErrorHelper.cs" />
<Compile Include="$(CommonPath)System\Threading\Tasks\TaskToApm.cs" Link="Common\System\Threading\Tasks\TaskToApm.cs" />
<Compile Include="System\Net\NetworkError.cs" />
<Compile Include="System\Net\NetworkException.cs" />
<Compile Include="System\Net\Connections\ConnectionBase.cs" />
<Compile Include="System\Net\Connections\ConnectionCloseMethod.cs" />
<Compile Include="System\Net\Connections\ConnectionExtensions.cs" />
Expand All @@ -20,13 +22,13 @@
<Compile Include="System\Net\Connections\Sockets\SocketsConnectionFactory.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\System.IO.Pipelines\ref\System.IO.Pipelines.csproj" />
<Reference Include="System.Runtime" />
<Reference Include="System.Memory" />
<Reference Include="System.Net.Primitives" />
<Reference Include="System.Net.Sockets" />
<Reference Include="System.Threading" />
<Reference Include="System.Threading.Tasks" />
<Reference Include="System.IO.Pipelines" />
<Reference Include="Microsoft.Win32.Primitives" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,7 @@ public override void GetObjectData(SerializationInfo serializationInfo, Streamin
/// <summary>Returns the specific kind of error.</summary>
public NetworkError NetworkError { get; }

private static string GetExceptionMessage(NetworkError error) => error switch
{
NetworkError.EndPointInUse => SR.networkerror_addressinuse,
NetworkError.TimedOut => SR.networkerror_timedout,
NetworkError.HostNotFound => SR.networkerror_hostnotfound,
NetworkError.ConnectionRefused => SR.networkerror_connectionrefused,
NetworkError.ConnectionAborted => SR.networkerror_connectionaborted,
NetworkError.ConnectionReset => SR.networkerror_connectionreset,
NetworkError.OperationAborted => SR.networkerror_operationaborted,
_ => SR.networkerror_other
};
// TODO: Better exception messages
safern marked this conversation as resolved.
Show resolved Hide resolved
private static string GetExceptionMessage(NetworkError error) => $"A network error occurred: {error}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -225,36 +225,6 @@ public async Task Connection_Pipe_ReadWrite_Success(EndPoint endPoint, SocketTyp
Assert.True(rr.Buffer.FirstSpan.SequenceEqual(sendData));
}

[Fact]
public async Task Connection_Stream_FailingOperation_ThowsNetworkException()
{
using var server = SocketTestServer.SocketTestServerFactory(SocketImplementationType.Async, IPAddress.Loopback);
using SocketsConnectionFactory factory = new SocketsConnectionFactory(SocketType.Stream, ProtocolType.Tcp);
using Connection connection = await factory.ConnectAsync(server.EndPoint);

connection.ConnectionProperties.TryGet(out Socket socket);
Stream stream = connection.Stream;
socket.Dispose();

Assert.Throws<NetworkException>(() => stream.Read(new byte[1], 0, 1));
Assert.Throws<NetworkException>(() => stream.Write(new byte[1], 0, 1));
}

[Fact]
public async Task Connection_Pipe_FailingOperation_ThowsNetworkException()
{
using var server = SocketTestServer.SocketTestServerFactory(SocketImplementationType.Async, IPAddress.Loopback);
using SocketsConnectionFactory factory = new SocketsConnectionFactory(SocketType.Stream, ProtocolType.Tcp);
using Connection connection = await factory.ConnectAsync(server.EndPoint);

connection.ConnectionProperties.TryGet(out Socket socket);
IDuplexPipe pipe = connection.Pipe;
socket.Dispose();

await Assert.ThrowsAsync<NetworkException>(() => pipe.Input.ReadAsync().AsTask());
await Assert.ThrowsAsync<NetworkException>(() => pipe.Output.WriteAsync(new byte[1]).AsTask());
}
Comment on lines -229 to -256
Copy link
Member

Choose a reason for hiding this comment

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

If we are keeping the rest of the code anyways, can we preserve these tests by refactoring the assertions for IOException? I would prefer not to loose them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As far as I can tell, the only reason these tests exist is to check for NetworkException specifically. So I'm not sure what we get by checking for IOException.

Copy link
Member

Choose a reason for hiding this comment

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

I agree that the assertion is less valuable in it's current form, but is it more likely that we are about to re-introduce NetworkException eventually? In that case keeping them around will ensure that we don't loose them by accident.

Copy link
Contributor

Choose a reason for hiding this comment

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

Depending on the direction we go, we will make a branch from master that reverts this PR and continue to iterate the API --so, I don't think we will lose anything.


[Theory]
[InlineData(false, false)]
[InlineData(false, true)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,9 @@
<Compile Include="$(CommonTestPath)System\Net\Sockets\SocketImplementationType.cs" Link="SocketCommon\SocketImplementationType.cs" />
<Compile Include="$(CommonTestPath)System\Threading\Tasks\TaskTimeoutExtensions.cs" Link="Common\System\Threading\Tasks\TaskTimeoutExtensions.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\System.IO.Pipelines\src\System.IO.Pipelines.csproj" />
<ProjectReference Include="..\..\..\System.Net.Connections\src\System.Net.Connections.csproj" />
</ItemGroup>

</Project>
2 changes: 0 additions & 2 deletions src/libraries/System.Net.Http/ref/System.Net.Http.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ public SocketsHttpHandler() { }
public static bool IsSupported { get { throw null; } }
public bool AllowAutoRedirect { get { throw null; } set { } }
public System.Net.DecompressionMethods AutomaticDecompression { get { throw null; } set { } }
public System.Net.Connections.ConnectionFactory? ConnectionFactory { get { throw null; } set { } }
public System.TimeSpan ConnectTimeout { get { throw null; } set { } }
[System.Diagnostics.CodeAnalysis.AllowNullAttribute]
public System.Net.CookieContainer CookieContainer { get { throw null; } set { } }
Expand All @@ -345,7 +344,6 @@ public SocketsHttpHandler() { }
public int MaxConnectionsPerServer { get { throw null; } set { } }
public int MaxResponseDrainSize { get { throw null; } set { } }
public int MaxResponseHeadersLength { get { throw null; } set { } }
public System.Func<System.Net.Http.HttpRequestMessage, System.Net.Connections.Connection, System.Threading.CancellationToken, System.Threading.Tasks.ValueTask<System.Net.Connections.Connection>>? PlaintextFilter { get { throw null; } set { } }
public System.TimeSpan PooledConnectionIdleTimeout { get { throw null; } set { } }
public System.TimeSpan PooledConnectionLifetime { get { throw null; } set { } }
public bool PreAuthenticate { get { throw null; } set { } }
Expand Down
1 change: 0 additions & 1 deletion src/libraries/System.Net.Http/ref/System.Net.Http.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<ProjectReference Include="..\..\System.Runtime\ref\System.Runtime.csproj" />
<ProjectReference Include="..\..\System.Net.Primitives\ref\System.Net.Primitives.csproj" />
<ProjectReference Include="..\..\System.Net.Sockets\ref\System.Net.Sockets.csproj" />
<ProjectReference Include="..\..\System.Net.Connections\ref\System.Net.Connections.csproj" />
<ProjectReference Include="..\..\System.Net.Security\ref\System.Net.Security.csproj" />
<ProjectReference Include="..\..\System.Security.Cryptography.X509Certificates\ref\System.Security.Cryptography.X509Certificates.csproj" />
<ProjectReference Include="..\..\System.Text.Encoding\ref\System.Text.Encoding.csproj" />
Expand Down
Loading