@@ -72,6 +72,7 @@ public abstract class ModelBase : IFullModel, IRecoverable
72
72
private readonly object m_eventLock = new object ( ) ;
73
73
private readonly object m_flowSendLock = new object ( ) ;
74
74
private readonly object m_shutdownLock = new object ( ) ;
75
+ private readonly object _rpcLock = new object ( ) ;
75
76
76
77
private readonly SynchronizedList < ulong > m_unconfirmedSet = new SynchronizedList < ulong > ( ) ;
77
78
@@ -358,36 +359,43 @@ public string ConnectionOpen(string virtualHost,
358
359
bool insist )
359
360
{
360
361
var k = new ConnectionOpenContinuation ( ) ;
361
- Enqueue ( k ) ;
362
- try
363
- {
364
- _Private_ConnectionOpen ( virtualHost , capabilities , insist ) ;
365
- }
366
- catch ( AlreadyClosedException )
362
+ lock ( _rpcLock )
367
363
{
368
- // let continuation throw OperationInterruptedException,
369
- // which is a much more suitable exception before connection
370
- // negotiation finishes
364
+ Enqueue ( k ) ;
365
+ try
366
+ {
367
+ _Private_ConnectionOpen ( virtualHost , capabilities , insist ) ;
368
+ }
369
+ catch ( AlreadyClosedException )
370
+ {
371
+ // let continuation throw OperationInterruptedException,
372
+ // which is a much more suitable exception before connection
373
+ // negotiation finishes
374
+ }
375
+ k . GetReply ( HandshakeContinuationTimeout ) ;
371
376
}
372
- k . GetReply ( HandshakeContinuationTimeout ) ;
377
+
373
378
return k . m_knownHosts ;
374
379
}
375
380
376
381
public ConnectionSecureOrTune ConnectionSecureOk ( byte [ ] response )
377
382
{
378
383
var k = new ConnectionStartRpcContinuation ( ) ;
379
- Enqueue ( k ) ;
380
- try
384
+ lock ( _rpcLock )
381
385
{
382
- _Private_ConnectionSecureOk ( response ) ;
383
- }
384
- catch ( AlreadyClosedException )
385
- {
386
- // let continuation throw OperationInterruptedException,
387
- // which is a much more suitable exception before connection
388
- // negotiation finishes
386
+ Enqueue ( k ) ;
387
+ try
388
+ {
389
+ _Private_ConnectionSecureOk ( response ) ;
390
+ }
391
+ catch ( AlreadyClosedException )
392
+ {
393
+ // let continuation throw OperationInterruptedException,
394
+ // which is a much more suitable exception before connection
395
+ // negotiation finishes
396
+ }
397
+ k . GetReply ( HandshakeContinuationTimeout ) ;
389
398
}
390
- k . GetReply ( HandshakeContinuationTimeout ) ;
391
399
return k . m_result ;
392
400
}
393
401
@@ -397,19 +405,22 @@ public ConnectionSecureOrTune ConnectionStartOk(IDictionary<string, object> clie
397
405
string locale )
398
406
{
399
407
var k = new ConnectionStartRpcContinuation ( ) ;
400
- Enqueue ( k ) ;
401
- try
402
- {
403
- _Private_ConnectionStartOk ( clientProperties , mechanism ,
404
- response , locale ) ;
405
- }
406
- catch ( AlreadyClosedException )
408
+ lock ( _rpcLock )
407
409
{
408
- // let continuation throw OperationInterruptedException,
409
- // which is a much more suitable exception before connection
410
- // negotiation finishes
410
+ Enqueue ( k ) ;
411
+ try
412
+ {
413
+ _Private_ConnectionStartOk ( clientProperties , mechanism ,
414
+ response , locale ) ;
415
+ }
416
+ catch ( AlreadyClosedException )
417
+ {
418
+ // let continuation throw OperationInterruptedException,
419
+ // which is a much more suitable exception before connection
420
+ // negotiation finishes
421
+ }
422
+ k . GetReply ( HandshakeContinuationTimeout ) ;
411
423
}
412
- k . GetReply ( HandshakeContinuationTimeout ) ;
413
424
return k . m_result ;
414
425
}
415
426
@@ -456,8 +467,11 @@ public void HandleCommand(ISession session, Command cmd)
456
467
public MethodBase ModelRpc ( MethodBase method , ContentHeaderBase header , byte [ ] body )
457
468
{
458
469
var k = new SimpleBlockingRpcContinuation ( ) ;
459
- TransmitAndEnqueue ( new Command ( method , header , body ) , k ) ;
460
- return k . GetReply ( this . ContinuationTimeout ) . Method ;
470
+ lock ( _rpcLock )
471
+ {
472
+ TransmitAndEnqueue ( new Command ( method , header , body ) , k ) ;
473
+ return k . GetReply ( this . ContinuationTimeout ) . Method ;
474
+ }
461
475
}
462
476
463
477
public void ModelSend ( MethodBase method , ContentHeaderBase header , byte [ ] body )
@@ -1146,10 +1160,12 @@ public void BasicCancel(string consumerTag)
1146
1160
{
1147
1161
var k = new BasicConsumerRpcContinuation { m_consumerTag = consumerTag } ;
1148
1162
1149
- Enqueue ( k ) ;
1150
-
1151
- _Private_BasicCancel ( consumerTag , false ) ;
1152
- k . GetReply ( this . ContinuationTimeout ) ;
1163
+ lock ( _rpcLock )
1164
+ {
1165
+ Enqueue ( k ) ;
1166
+ _Private_BasicCancel ( consumerTag , false ) ;
1167
+ k . GetReply ( this . ContinuationTimeout ) ;
1168
+ }
1153
1169
lock ( m_consumers )
1154
1170
{
1155
1171
m_consumers . Remove ( consumerTag ) ;
@@ -1180,12 +1196,15 @@ public string BasicConsume(string queue,
1180
1196
1181
1197
var k = new BasicConsumerRpcContinuation { m_consumer = consumer } ;
1182
1198
1183
- Enqueue ( k ) ;
1184
- // Non-nowait. We have an unconventional means of getting
1185
- // the RPC response, but a response is still expected.
1186
- _Private_BasicConsume ( queue , consumerTag , noLocal , autoAck , exclusive ,
1187
- /*nowait:*/ false , arguments ) ;
1188
- k . GetReply ( this . ContinuationTimeout ) ;
1199
+ lock ( _rpcLock )
1200
+ {
1201
+ Enqueue ( k ) ;
1202
+ // Non-nowait. We have an unconventional means of getting
1203
+ // the RPC response, but a response is still expected.
1204
+ _Private_BasicConsume ( queue , consumerTag , noLocal , autoAck , exclusive ,
1205
+ /*nowait:*/ false , arguments ) ;
1206
+ k . GetReply ( this . ContinuationTimeout ) ;
1207
+ }
1189
1208
string actualConsumerTag = k . m_consumerTag ;
1190
1209
1191
1210
return actualConsumerTag ;
@@ -1195,9 +1214,13 @@ public BasicGetResult BasicGet(string queue,
1195
1214
bool autoAck )
1196
1215
{
1197
1216
var k = new BasicGetRpcContinuation ( ) ;
1198
- Enqueue ( k ) ;
1199
- _Private_BasicGet ( queue , autoAck ) ;
1200
- k . GetReply ( this . ContinuationTimeout ) ;
1217
+ lock ( _rpcLock )
1218
+ {
1219
+ Enqueue ( k ) ;
1220
+ _Private_BasicGet ( queue , autoAck ) ;
1221
+ k . GetReply ( this . ContinuationTimeout ) ;
1222
+ }
1223
+
1201
1224
return k . m_result ;
1202
1225
}
1203
1226
@@ -1261,9 +1284,12 @@ public void BasicRecover(bool requeue)
1261
1284
{
1262
1285
var k = new SimpleBlockingRpcContinuation ( ) ;
1263
1286
1264
- Enqueue ( k ) ;
1265
- _Private_BasicRecover ( requeue ) ;
1266
- k . GetReply ( this . ContinuationTimeout ) ;
1287
+ lock ( _rpcLock )
1288
+ {
1289
+ Enqueue ( k ) ;
1290
+ _Private_BasicRecover ( requeue ) ;
1291
+ k . GetReply ( this . ContinuationTimeout ) ;
1292
+ }
1267
1293
}
1268
1294
1269
1295
public abstract void BasicRecoverAsync ( bool requeue ) ;
@@ -1559,9 +1585,12 @@ private QueueDeclareOk QueueDeclare(string queue, bool passive, bool durable, bo
1559
1585
bool autoDelete , IDictionary < string , object > arguments )
1560
1586
{
1561
1587
var k = new QueueDeclareRpcContinuation ( ) ;
1562
- Enqueue ( k ) ;
1563
- _Private_QueueDeclare ( queue , passive , durable , exclusive , autoDelete , false , arguments ) ;
1564
- k . GetReply ( this . ContinuationTimeout ) ;
1588
+ lock ( _rpcLock )
1589
+ {
1590
+ Enqueue ( k ) ;
1591
+ _Private_QueueDeclare ( queue , passive , durable , exclusive , autoDelete , false , arguments ) ;
1592
+ k . GetReply ( this . ContinuationTimeout ) ;
1593
+ }
1565
1594
return k . m_result ;
1566
1595
}
1567
1596
0 commit comments