[CSHARP-881] MongoServer.BuildInfo always null at start, magically populates later Created: 20/Dec/13  Updated: 20/Mar/14  Resolved: 23/Dec/13

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 1.8.3
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Andrew Ryder (Inactive) Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

The following code snippet illustrates curious behaviour;

var srv = new MongoClient( "mongodb://Boomtime:27017" ).GetServer();
 
var binfo = srv.BuildInfo;
Console.WriteLine( "via .BuildInfo: {0}", null == binfo ? "[null]" : binfo.VersionString );
 
var resbi = srv.GetDatabase( "test" ).RunCommand( "buildInfo" );
Console.WriteLine( "via .RunCommand: {0}", resbi.Response["version"] );
 
var redux = srv.BuildInfo;
Console.WriteLine( "via .BuildInfo: {0}", null == redux ? "[null]" : redux.VersionString );

Example output of running the code;

via .BuildInfo: [null]
via .RunCommand: 2.4.6
via .BuildInfo: 2.4.6

If .BuildInfo is queried as the first order of business on a new server connection, then it appears to always yield null. After some other, possibly unrelated, commands have returned successfully, the .BuildInfo is now populated.

A value of null for BuildInfo on a valid connection is unexpected and should be documented if intended.

Assuming that behaviour is correct, the library now lacks a signal to indicate when the member has transitioned to a valid state. Which in turn requires polling or knowledge of the implementation to be able to make use of it.

In practice, it is not clear how to make robust use of this member.



 Comments   
Comment by Craig Wilson [ 23/Dec/13 ]

This behavior will not be changed.

Comment by Craig Wilson [ 20/Dec/13 ]

BuildInfo is populated after the server has connected. When you are first testing it, you haven't connected to the database yet. After you run a command, query, update, etc..., you will have connected to the database and this property will be populated. So, to make this more robust, simply do a srv.Connect() before testing the property.

In addition, as this property is hanging off of MongoServer (which does not correlate to a specific server, but rather to a group or servers), it is not representative that you could actually be running a mixed version cluster. As such, it would be better to use buildInfos = srv.Instances.Select(x => x.BuildInfo); This will provide you the build info for each instance in the cluster.

Generated at Wed Feb 07 21:38:06 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.