[CSHARP-547] Use of $csharpnull when serializing a BsonNull whose value is C# null halts replication (and in 2.2 the secondaries crash) Created: 23/Aug/12  Updated: 20/Mar/14  Resolved: 23/Aug/12

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

Type: Bug Priority: Minor - P4
Reporter: Robert Stam Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-6833 Secondary crashes when replicating a ... Closed
Backwards Compatibility: Minor Change

 Description   

The C# driver uses

{ $csharpnull : true }

to represent a BsonNull property whose value is C# null. For example:

public class C
{
    public BsonNull a;
    public BsonNull b;
}
 
var c = new C { a = BsonNull.Value, b = null };
Console.WriteLine(c.ToJson());

results in:

{ "a" : null, "b" : { "$csharpnull" : true } }

The C# driver needs to use some other representation for BsonNull values of C# null because this representation either causes replication to halt (prior to server 2.2) or the secondaries to crash (in server 2.2 rc0 and rc1).

This is also a server bug, in the sense that no value that a client driver provides should be allowed to halt replication or crash secondaries. If the server considers this representation to be invalid then it should have been rejected outright by the primary.



 Comments   
Comment by auto [ 24/Aug/12 ]

Author:

{u'date': u'2012-08-23T11:42:13-07:00', u'name': u'rstam', u'email': u'robert@10gen.com'}

Message: CSHARP-547: Replace use of $csharpnull with _csharpnull because the leading "$" causes secondaries to crash in server 2.2. The new representation will always be used when serializing, but both representation are supported when deserializing. This is a rare edge case and almost no one should be affected by it.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/2647c3b77c5caeb1c67b8b75c9a78ee5d55d8992

Comment by Robert Stam [ 23/Aug/12 ]

The proposed fix is to replace $csharpnull with _csharpnull (replacing the "$" with "_").

During deserialization either form will be accepted so that legacy documents can still be read.

Comment by Robert Stam [ 23/Aug/12 ]

Linking to SERVER issue that suggests that the primary should have protected itself against a document it didn't consider valid instead of letting it replicate to the secondaries where it caused the secondaries to crash.

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