Skip to content

Commit a2cf033

Browse files
committed
CSHARP-1531: Force GetMores to use a new connection every time.
1 parent b62b11e commit a2cf033

File tree

6 files changed

+37
-29
lines changed

6 files changed

+37
-29
lines changed

src/MongoDB.Driver.Core/Core/Operations/AggregateOperation.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,9 @@ private AsyncCursor<TResult> CreateCursor(IChannelSourceHandle channelSource, IC
258258

259259
private AsyncCursor<TResult> CreateCursorFromCursorResult(IChannelSourceHandle channelSource, BsonDocument command, AggregateResult result)
260260
{
261+
var getMoreChannelSource = new ServerChannelSource(channelSource.Server);
261262
return new AsyncCursor<TResult>(
262-
channelSource.Fork(),
263+
getMoreChannelSource,
263264
CollectionNamespace,
264265
command,
265266
result.Results,

src/MongoDB.Driver.Core/Core/Operations/FindCommandOperation.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,9 @@ private BsonDocument CreateCommand(ServerDescription serverDescription, ReadPref
440440

441441
private AsyncCursor<TDocument> CreateCursor(IChannelSourceHandle channelSource, CursorBatch<TDocument> batch, bool slaveOk)
442442
{
443+
var getMoreChannelSource = new ServerChannelSource(channelSource.Server);
443444
return new AsyncCursor<TDocument>(
444-
channelSource.Fork(),
445+
getMoreChannelSource,
445446
_collectionNamespace,
446447
_filter ?? new BsonDocument(),
447448
batch.Documents,

src/MongoDB.Driver.Core/Core/Operations/FindOpcodeOperation.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,9 @@ public IReadOperation<BsonDocument> ToExplainOperation(ExplainVerbosity verbosit
523523
// private methods
524524
private IAsyncCursor<TDocument> CreateCursor(IChannelSourceHandle channelSource, BsonDocument query, CursorBatch<TDocument> batch)
525525
{
526+
var getMoreChannelSource = new ServerChannelSource(channelSource.Server);
526527
return new AsyncCursor<TDocument>(
527-
channelSource.Fork(),
528+
getMoreChannelSource,
528529
_collectionNamespace,
529530
query,
530531
batch.Documents,

src/MongoDB.Driver.Core/Core/Operations/ListCollectionsUsingCommandOperation.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,10 @@ private ReadCommandOperation<BsonDocument> CreateOperation()
128128

129129
private IAsyncCursor<BsonDocument> CreateCursor(IChannelSourceHandle channelSource, BsonDocument command, BsonDocument result)
130130
{
131+
var getMoreChannelSource = new ServerChannelSource(channelSource.Server);
131132
var cursorDocument = result["cursor"].AsBsonDocument;
132133
var cursor = new AsyncCursor<BsonDocument>(
133-
channelSource.Fork(),
134+
getMoreChannelSource,
134135
CollectionNamespace.FromFullName(cursorDocument["ns"].AsString),
135136
command,
136137
cursorDocument["firstBatch"].AsBsonArray.OfType<BsonDocument>().ToList(),

src/MongoDB.Driver.Core/Core/Operations/ListIndexesUsingCommandOperation.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,10 @@ private ReadCommandOperation<BsonDocument> CreateOperation()
134134

135135
private IAsyncCursor<BsonDocument> CreateCursor(IChannelSourceHandle channelSource, BsonDocument result, BsonDocument command)
136136
{
137+
var getMoreChannelSource = new ServerChannelSource(channelSource.Server);
137138
var cursorDocument = result["cursor"].AsBsonDocument;
138139
var cursor = new AsyncCursor<BsonDocument>(
139-
channelSource.Fork(),
140+
getMoreChannelSource,
140141
CollectionNamespace.FromFullName(cursorDocument["ns"].AsString),
141142
command,
142143
cursorDocument["firstBatch"].AsBsonArray.OfType<BsonDocument>().ToList(),

src/MongoDB.Driver.Core/Core/Operations/ParallelScanOperation.cs

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -155,33 +155,36 @@ private IReadOnlyList<IAsyncCursor<TDocument>> CreateCursors(IChannelSourceHandl
155155
{
156156
var cursors = new List<AsyncCursor<TDocument>>();
157157

158-
foreach (var cursorDocument in result["cursors"].AsBsonArray.Select(v => v["cursor"].AsBsonDocument))
158+
using (var getMoreChannelSource = new ChannelSourceHandle(new ServerChannelSource(channelSource.Server)))
159159
{
160-
var cursorId = cursorDocument["id"].ToInt64();
161-
var firstBatch = cursorDocument["firstBatch"].AsBsonArray.Select(v =>
160+
foreach (var cursorDocument in result["cursors"].AsBsonArray.Select(v => v["cursor"].AsBsonDocument))
162161
{
163-
var bsonDocument = (BsonDocument)v;
164-
using (var reader = new BsonDocumentReader(bsonDocument))
162+
var cursorId = cursorDocument["id"].ToInt64();
163+
var firstBatch = cursorDocument["firstBatch"].AsBsonArray.Select(v =>
165164
{
166-
var context = BsonDeserializationContext.CreateRoot(reader);
167-
var document = _serializer.Deserialize(context);
168-
return document;
169-
}
170-
})
171-
.ToList();
172-
173-
var cursor = new AsyncCursor<TDocument>(
174-
channelSource.Fork(),
175-
_collectionNamespace,
176-
command,
177-
firstBatch,
178-
cursorId,
179-
_batchSize ?? 0,
180-
0, // limit
181-
_serializer,
182-
_messageEncoderSettings);
183-
184-
cursors.Add(cursor);
165+
var bsonDocument = (BsonDocument)v;
166+
using (var reader = new BsonDocumentReader(bsonDocument))
167+
{
168+
var context = BsonDeserializationContext.CreateRoot(reader);
169+
var document = _serializer.Deserialize(context);
170+
return document;
171+
}
172+
})
173+
.ToList();
174+
175+
var cursor = new AsyncCursor<TDocument>(
176+
getMoreChannelSource.Fork(),
177+
_collectionNamespace,
178+
command,
179+
firstBatch,
180+
cursorId,
181+
_batchSize ?? 0,
182+
0, // limit
183+
_serializer,
184+
_messageEncoderSettings);
185+
186+
cursors.Add(cursor);
187+
}
185188
}
186189

187190
return cursors;

0 commit comments

Comments
 (0)