IPV6 stack is required for .NET 5
We ran into a weird problem with Elasticsearch.NET package when upgraded to .net5. Our docker machines don't have ipv6, specifically they don't have /proc/net/tcp6, they have /proc/net/tcp.
In StringParsingHelpers.Connections.cs:
internal static TcpConnectionInformation[] ParseActiveTcpConnectionsFromFiles(string tcp4ConnectionsFile, string tcp6ConnectionsFile)
{
if (!File.Exists(tcp4ConnectionsFile) || !File.Exists(tcp6ConnectionsFile))
{
throw new PlatformNotSupportedException(SR.net_InformationUnavailableOnPlatform);
}
/proc/net/tcp6 is a required file and the exception will be thrown if its missing.
Unhandled exception. System.AggregateException: One or more errors occurred. (The information requested is unavailable on the current platform.)
---> Elasticsearch.Net.UnexpectedElasticsearchClientException: The information requested is unavailable on the current platform.
---> System.PlatformNotSupportedException: The information requested is unavailable on the current platform.
at System.Net.NetworkInformation.StringParsingHelpers.ParseActiveTcpConnectionsFromFiles(String tcp4ConnectionsFile, String tcp6ConnectionsFile) in /_/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/StringParsingHelpers.Connections.cs:line 36
at System.Net.NetworkInformation.LinuxIPGlobalProperties.GetActiveTcpConnections() in /_/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/LinuxIPGlobalProperties.cs:line 10
at Elasticsearch.Net.Diagnostics.TcpStats.GetActiveTcpConnections()
at Elasticsearch.Net.Diagnostics.TcpStats.GetStates()
at Elasticsearch.Net.HttpConnection.RequestAsync[TResponse](RequestData requestData, CancellationToken cancellationToken)
at Elasticsearch.Net.RequestPipeline.CallElasticsearchAsync[TResponse](RequestData requestData, CancellationToken cancellationToken)
at Elasticsearch.Net.Transport`1.RequestAsync[TResponse](HttpMethod method, String path, CancellationToken cancellationToken, PostData data, IRequestParameters requestParameters)
I guess you should report it to https://github.com/dotnet/runtime/
Tagging subscribers to this area: @dotnet/ncl See info in area-owners.md if you want to be subscribed.
Issue Details
We ran into a weird problem with Elasticsearch.NET package when upgraded to .net5. Our docker machines don't have ipv6, specifically they don't have /proc/net/tcp6, they have /proc/net/tcp.
In StringParsingHelpers.Connections.cs:
internal static TcpConnectionInformation[] ParseActiveTcpConnectionsFromFiles(string tcp4ConnectionsFile, string tcp6ConnectionsFile)
{
if (!File.Exists(tcp4ConnectionsFile) || !File.Exists(tcp6ConnectionsFile))
{
throw new PlatformNotSupportedException(SR.net_InformationUnavailableOnPlatform);
}
/proc/net/tcp6 is a required file and the exception will be thrown if its missing.
Unhandled exception. System.AggregateException: One or more errors occurred. (The information requested is unavailable on the current platform.)
---> Elasticsearch.Net.UnexpectedElasticsearchClientException: The information requested is unavailable on the current platform.
---> System.PlatformNotSupportedException: The information requested is unavailable on the current platform.
at System.Net.NetworkInformation.StringParsingHelpers.ParseActiveTcpConnectionsFromFiles(String tcp4ConnectionsFile, String tcp6ConnectionsFile) in /_/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/StringParsingHelpers.Connections.cs:line 36
at System.Net.NetworkInformation.LinuxIPGlobalProperties.GetActiveTcpConnections() in /_/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/LinuxIPGlobalProperties.cs:line 10
at Elasticsearch.Net.Diagnostics.TcpStats.GetActiveTcpConnections()
at Elasticsearch.Net.Diagnostics.TcpStats.GetStates()
at Elasticsearch.Net.HttpConnection.RequestAsync[TResponse](RequestData requestData, CancellationToken cancellationToken)
at Elasticsearch.Net.RequestPipeline.CallElasticsearchAsync[TResponse](RequestData requestData, CancellationToken cancellationToken)
at Elasticsearch.Net.Transport`1.RequestAsync[TResponse](HttpMethod method, String path, CancellationToken cancellationToken, PostData data, IRequestParameters requestParameters)
| Author: | thebitllc |
|---|---|
| Assignees: | - |
| Labels: |
|
| Milestone: | - |
Hi @thebitllc, could you tell us on which .NET version it worked? Could this be a change in elastic package rather than .NET? I looked into .NET Core 3.1 sources and the very same code was already there: https://github.com/dotnet/corefx/blob/49360a426aa2e588ca6758c76776bad7bed2834f/src/System.Net.NetworkInformation/src/System/Net/NetworkInformation/StringParsingHelpers.Connections.cs#L33-L38
internal static TcpConnectionInformation[] ParseActiveTcpConnectionsFromFiles(string tcp4ConnectionsFile, string tcp6ConnectionsFile)
{
if (!File.Exists(tcp4ConnectionsFile) || !File.Exists(tcp6ConnectionsFile))
{
throw new PlatformNotSupportedException(SR.net_InformationUnavailableOnPlatform);
}
I wonder if we should avoid parsing IPv6 files when IPv6 is disabled by System.Net.DisableIPv6 / DOTNET_SYSTEM_NET_DISABLEIPV6 (introduced in 6.0 via #55012). @antonfirsov any thoughts?
I wonder if we should avoid parsing IPv6 files when IPv6 is disabled
More generally we shouldn't fail to produce IPv4 info on a machine that lacks IPv6 support. It sounds like that's what's happening?
Yes, we throw in GetActiveTcpConnections, GetActiveTcpListeners, GetActiveUdpListeners (maybe others?) when the IPv6 files are missing. We can instead just ignore them, or we can consider only throwing when Socket.OSSupportsIPv6 == true.
Our docker machines don't have ipv6
@thebitllc I wonder what does this exactly mean. Is it a result of some sort of docker configuration? What is the value of Socket.OSSupportsIPv6?
Regarding the specific user complaint, @ManickaP is right in https://github.com/dotnet/runtime/issues/59015#issuecomment-917965251, the GetActiveTcpConnections behavior is here since 1.0, .NET 5 shouldn't have broken anything, unless the source of the problem is somewhere else, and the call to GetActiveTcpConnections is just a side effect.
@antonfirsov That means that /proc/net/tcp6 doesn't exist. Specifically it's a k8 cluster and in my limited knowledge tcp6 stack is still in beta. https://kubernetes.io/docs/concepts/services-networking/dual-stack/ . I can try to get this value of Socket.OSSupportsIPv6.
There are few things that may control this behavior i.e. docker/k8, the base image (ubi8/dotnet-50-runtime)
@ManickaP It worked fine in netcoreapp3.1 with aspnetcore-runtime-3.1 base image. We didn't upgrade Elastic nuget. But since I was pointed out that this code was the same in 3.1, I'd need to look into what may have caused the exception now.
I don't think we should link to DOTNET_SYSTEM_NET_DISABLEIPV6. This is to force IPv4 when IPv6 is available but I feel this is different. The /proc may be missing for various reasons - like Docker/Kuberneties and we had similar issue on WSL before.
I would suggest to work out variant if #52376 and possibly throw only if neither AddressFamily is available. (and I would make that symmetric e.g. start getting ready for IPv6 only system)
From k8 -> Socket.OSSupportsIPv6:False. This isn't a blocker right now, as we can bypass the call to GetActiveTcpConnections() from Elastic's NEST by disabling the .EnableTcpStats(false) in the connection settings.
@thebitllc thanks for info. Can you please help us identify the difference between 3.1 and 5.0 in your environment? That seems to be the last piece of the puzzle ...
Side note that the GetActiveTcpConnections is not cheap especially with large number of connection. Just be cautions about it in production code @thebitllc. It may be best to isolate small repro that work in 3.1 but not on 5.0. I think there is space for improvements but the difference between 3.1 and 5.0 is still curious.
I don't have a direct access to k8, so trying to replicate a similar setup in local docker, so I can remove /proc/net/tcp6 file and run some basic console code there.
edit: I have a lot of problems of removing /proc/net/tcp6 outside of our k8. I tried all possible options for linux vm, local docker and etc. I am going to try to install k8/kong in a vm.. I'll update on my progress.
edit2: I compiled a custom linux kernel in vm to remove tcp6 stack. Proceeding with tests with netcore 3.1 vs net 5.0
Ok, so on this VM both 3.1.100 and 5.0 throws the same exception. So since both fail, it could others things like a different docker base image lacks tcp6 support, or something got changed in the k8 environment. So the problem isn't specific to NET5. I tested 2.1, 3.1 and 5.0 and the same problems across all three. In my opinion its still a problem if sometimes linux kernel lacks TCP6 support.
root@debian1:~/test-development-31# /root/.dotnet/dotnet /root/test-development-31/bin/Release/netcoreapp3.1/test.dll
Unhandled exception. Elasticsearch.Net.UnexpectedElasticsearchClientException: The information requested is unavailable on the current platform.
---> System.PlatformNotSupportedException: The information requested is unavailable on the current platform.
at System.Net.NetworkInformation.StringParsingHelpers.ParseActiveTcpConnectionsFromFiles(String tcp4ConnectionsFile, String tcp6ConnectionsFile)
at System.Net.NetworkInformation.LinuxIPGlobalProperties.GetActiveTcpConnections()
at Elasticsearch.Net.Diagnostics.TcpStats.GetActiveTcpConnections()
at Elasticsearch.Net.Diagnostics.TcpStats.GetStates()
at Elasticsearch.Net.HttpConnection.Request[TResponse](RequestData requestData)
at Elasticsearch.Net.RequestPipeline.CallElasticsearch[TResponse](RequestData requestData)
at Elasticsearch.Net.Transport`1.Request[TResponse](HttpMethod method, String path, PostData data, IRequestParameters requestParameters)
--- End of inner exception stack trace ---
at Elasticsearch.Net.Transport`1.Request[TResponse](HttpMethod method, String path, PostData data, IRequestParameters requestParameters)
at Elasticsearch.Net.ElasticLowLevelClient.DoRequest[TResponse](HttpMethod method, String path, PostData data, IRequestParameters requestParameters)
at Nest.ElasticClient.DoRequest[TRequest,TResponse](TRequest p, IRequestParameters parameters, Action`2 forceConfiguration)
at Nest.ElasticClient.Index[TDocument](IIndexRequest`1 request)
at Nest.ElasticClient.Index[TDocument](TDocument document, Func`2 selector)
at Nest.ElasticClient.IndexDocument[TDocument](TDocument document)
at test.Program.Main(String[] args) in /root/test-development-31/Program.cs:line 19
Aborted