I run self-hosted MongoDB standalone and ReplicaSet on CentOS machines.
My clients are written in C# against .NETCore, I use Fedora 32 to develop my servers. The server exist for several years now.
I upgraded from .NETCore 2.1. to 3.1 without any problems.
I upgraded to the latest MongoDB Driver WITH SOME PROBLEMS…
So the driver I use is 2.11.0.0. This seams to be the first driver supporting .NET Standard 2.0…
I have a connect string to a Standalone Installation which looks as follows and is very simple (no options):
mongodb://bb-infraserver.gala.int:37017
I use this URL on 4 of my servers WITHOUT ANY problems.
But ONE Server throws the following exception (which I have never seen before…). Here is the simple C# code
try
{
var client = new MongoClient("mongodb://bb-infraserver.gala.int:37017");
}
catch (Exception e)
{
Log.Logger.Error($"MongoDB driver exception: {e.Message}. Exceptions: {e.GetAllExceptions()}");
throw;
}
This is the exception which is thrown:
System.IO.IOException: Invalid argument
at System.IO.FileStream.CheckFileCall(Int64 result, Boolean ignoreNotSupported) in /_/src/System.Private.CoreLib/shared/System/IO/FileStream.Unix.cs:828
at System.IO.FileStream.ReadNative(Span`1 buffer) in /_/src/System.Private.CoreLib/shared/System/IO/FileStream.Unix.cs:495
at System.IO.FileStream.ReadSpan(Span`1 destination) in /_/src/System.Private.CoreLib/shared/System/IO/FileStream.Unix.cs:418
at System.IO.FileStream.Read(Byte[] array, Int32 offset, Int32 count) in /_/src/System.Private.CoreLib/shared/System/IO/FileStream.cs:304
at System.IO.StreamReader.ReadBuffer() in /_/src/System.Private.CoreLib/shared/System/IO/StreamReader.cs:594
at System.IO.StreamReader.ReadToEnd() in /_/src/System.Private.CoreLib/shared/System/IO/StreamReader.cs:415
at System.IO.File.InternalReadAllText(String path, Encoding encoding) in /_/src/System.IO.FileSystem/src/System/IO/File.cs:296
at System.IO.File.ReadAllText(String path) in /_/src/System.IO.FileSystem/src/System/IO/File.cs:274
at System.Net.NetworkInformation.StringParsingHelpers.ParseRawLongFile(String filePath) in /_/src/System.Net.NetworkInformation/src/System/Net/NetworkInformation/StringParsingHelpers.Misc.cs:64
at System.Net.NetworkInformation.LinuxNetworkInterface.GetSpeed(String name) in /_/src/System.Net.NetworkInformation/src/System/Net/NetworkInformation/LinuxNetworkInterface.cs:202
I tried to debug this a bit deeper and found a file LinuxNetworkInterface.cs
and there a method
private static long? GetSpeed(string name)
{
try
{
string path = Path.Combine(NetworkFiles.SysClassNetFolder, name, NetworkFiles.SpeedFileName);
long megabitsPerSecond = StringParsingHelpers.ParseRawLongFile(path);
return megabitsPerSecond == -1
? megabitsPerSecond
: megabitsPerSecond * 1_000_000; // Value must be returned in bits per second, not megabits.
}
catch (Exception) // Ignore any problems accessing or parsing the file.
{
return null;
}
}
This method is called when doing name resolution which seems to have its origin from a method in the MongoDB driver called MongoUrlBuilder.Parse()
. The value of the passed name
parameter is “Io” and then it crashes when it tries to build the path with the above exception. This does NOT happen with any of the 2.10.x drivers which support only .NETStandard 1.5.
I must say that my MongoDB servers are still Version 4.0.
Any idea what the problem could be?