File tree 2 files changed +29
-1
lines changed
2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -384,7 +384,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
384
384
} else {
385
385
// Get the first orphaned operation description.
386
386
const entry = this [ kQueue ] . entries ( ) . next ( ) ;
387
- if ( entry ) {
387
+ if ( entry . value !== undefined ) {
388
388
const [ requestId , orphaned ] : [ number , OperationDescription ] = entry . value ;
389
389
// If the orphaned operation description exists then set it.
390
390
operationDescription = orphaned ;
Original file line number Diff line number Diff line change @@ -287,6 +287,34 @@ describe('new Connection()', function () {
287
287
} ) ;
288
288
} ) ;
289
289
290
+ context ( 'when no operation description is in the queue' , function ( ) {
291
+ const document = { ok : 1 } ;
292
+
293
+ beforeEach ( function ( ) {
294
+ // @ts -expect-error: driverSocket does not fully satisfy the stream type, but that's okay
295
+ connection = sinon . spy ( new Connection ( driverSocket , connectionOptionsDefaults ) ) ;
296
+ connection . isMonitoringConnection = true ;
297
+ const queueSymbol = getSymbolFrom ( connection , 'queue' ) ;
298
+ queue = connection [ queueSymbol ] ;
299
+
300
+ // Emit a message that matches the existing operation description.
301
+ const msg = generateOpMsgBuffer ( document ) ;
302
+ const msgHeader : MessageHeader = {
303
+ length : msg . readInt32LE ( 0 ) ,
304
+ requestId : 2 ,
305
+ responseTo : 1 ,
306
+ opCode : msg . readInt32LE ( 12 )
307
+ } ;
308
+ const msgBody = msg . subarray ( 16 ) ;
309
+
310
+ const message = new BinMsg ( msg , msgHeader , msgBody ) ;
311
+ connection . onMessage ( message ) ;
312
+ } ) ;
313
+
314
+ it ( 'does not error' , function ( ) {
315
+ } ) ;
316
+ } ) ;
317
+
290
318
context ( 'when more than one operation description is in the queue' , function ( ) {
291
319
let spyOne ;
292
320
let spyTwo ;
You can’t perform that action at this time.
0 commit comments