Skip to content

Commit 9c8b41b

Browse files
author
Simon MacMullen
committed
Merged bug 21848 into amqp_0_9_1
2 parents 49ac793 + 6aa2359 commit 9c8b41b

File tree

2 files changed

+37
-28
lines changed

2 files changed

+37
-28
lines changed

projects/client/RabbitMQ.Client/src/client/impl/ConnectionBase.cs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -787,12 +787,13 @@ public void NotifyReceivedCloseOk()
787787
TerminateMainloop();
788788
m_closed = true;
789789
}
790-
790+
791791
///<summary>
792792
/// Sets the channel named in the SoftProtocolException into
793793
/// "quiescing mode", where we issue a channel.close and
794-
/// ignore everything up to the channel.close-ok reply that
795-
/// should eventually arrive.
794+
/// ignore everything except for subsequent channel.close
795+
/// messages and the channel.close-ok reply that should
796+
/// eventually arrive.
796797
///</summary>
797798
///<remarks>
798799
///<para>
@@ -817,23 +818,12 @@ public void NotifyReceivedCloseOk()
817818
///</para>
818819
///</remarks>
819820
public void QuiesceChannel(SoftProtocolException pe) {
820-
// First, construct the close request and QuiescingSession
821-
// that we'll use during the quiesce process.
822-
823-
Command request;
824-
int replyClassId;
825-
int replyMethodId;
826-
Protocol.CreateChannelClose(pe.ReplyCode,
827-
pe.Message,
828-
out request,
829-
out replyClassId,
830-
out replyMethodId);
821+
// Construct the QuiescingSession that we'll use during
822+
// the quiesce process.
831823

832824
ISession newSession = new QuiescingSession(this,
833825
pe.Channel,
834-
pe.ShutdownReason,
835-
replyClassId,
836-
replyMethodId);
826+
pe.ShutdownReason);
837827

838828
// Here we detach the session from the connection. It's
839829
// still alive: it just won't receive any further frames
@@ -852,7 +842,7 @@ public void QuiesceChannel(SoftProtocolException pe) {
852842
// our peer. The peer will respond through the lower
853843
// layers - specifically, through the QuiescingSession we
854844
// installed above.
855-
newSession.Transmit(request);
845+
newSession.Transmit(ChannelCloseWrapper(pe.ReplyCode, pe.Message));
856846
}
857847

858848
public void HandleMainLoopException(ShutdownEventArgs reason) {
@@ -960,7 +950,19 @@ public Command ConnectionCloseWrapper(ushort reasonCode, string reasonText)
960950
out replyClassId,
961951
out replyMethodId);
962952
return request;
963-
}
953+
}
954+
955+
protected Command ChannelCloseWrapper(ushort reasonCode, string reasonText)
956+
{
957+
Command request;
958+
int replyClassId, replyMethodId;
959+
Protocol.CreateChannelClose(reasonCode,
960+
reasonText,
961+
out request,
962+
out replyClassId,
963+
out replyMethodId);
964+
return request;
965+
}
964966

965967
private static uint NegotiatedMaxValue(uint clientValue, uint serverValue)
966968
{

projects/client/RabbitMQ.Client/src/client/impl/QuiescingSession.cs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,45 +65,52 @@
6565
// the versions we support*. Obviously we may need to revisit this if
6666
// that ever changes.
6767
using CommonFraming = RabbitMQ.Client.Framing.v0_9;
68+
using CommonFramingSpecs = RabbitMQ.Client.Framing.Impl.v0_9;
6869

6970
namespace RabbitMQ.Client.Impl
7071
{
7172
///<summary>Small ISession implementation used during channel quiescing.</summary>
7273
public class QuiescingSession: SessionBase
7374
{
7475
public ShutdownEventArgs m_reason;
75-
public int m_replyClassId;
76-
public int m_replyMethodId;
7776

7877
public QuiescingSession(ConnectionBase connection,
7978
int channelNumber,
80-
ShutdownEventArgs reason,
81-
int replyClassId,
82-
int replyMethodId)
79+
ShutdownEventArgs reason)
8380
: base(connection, channelNumber)
8481
{
8582
m_reason = reason;
86-
m_replyClassId = replyClassId;
87-
m_replyMethodId = replyMethodId;
8883
}
8984

9085
public override void HandleFrame(Frame frame)
9186
{
9287
if (frame.Type == CommonFraming.Constants.FrameMethod) {
9388
MethodBase method = Connection.Protocol.DecodeMethodFrom(frame.GetReader());
94-
if ((method.ProtocolClassId == m_replyClassId)
95-
&& (method.ProtocolMethodId == m_replyMethodId))
89+
if ((method.ProtocolClassId == CommonFramingSpecs.ChannelCloseOk.ClassId)
90+
&& (method.ProtocolMethodId == CommonFramingSpecs.ChannelCloseOk.MethodId))
9691
{
9792
// This is the reply we were looking for. Release
9893
// the channel with the reason we were passed in
9994
// our constructor.
10095
Close(m_reason);
10196
return;
10297
}
98+
else if ((method.ProtocolClassId == CommonFramingSpecs.ChannelClose.ClassId)
99+
&& (method.ProtocolMethodId == CommonFramingSpecs.ChannelClose.MethodId))
100+
{
101+
// We're already shutting down the channel, so
102+
// just send back an ok.
103+
Transmit(CreateChannelCloseOk());
104+
return;
105+
}
103106
}
104107

105108
// Either a non-method frame, or not what we were looking
106109
// for. Ignore it - we're quiescing.
107110
}
111+
112+
protected Command CreateChannelCloseOk() {
113+
return new Command(new CommonFramingSpecs.ConnectionCloseOk());
114+
}
108115
}
109116
}

0 commit comments

Comments
 (0)