Skip to content

Commit fdaddd9

Browse files
committed
* Use finally to ensure payload is returned if necessary.
1 parent ad53338 commit fdaddd9

File tree

1 file changed

+39
-34
lines changed

1 file changed

+39
-34
lines changed

projects/RabbitMQ.Client/client/impl/Connection.Receive.cs

+39-34
Original file line numberDiff line numberDiff line change
@@ -133,51 +133,56 @@ await ProcessFrameAsync(asyncFrame, mainLoopCancellationToken)
133133
private async Task ProcessFrameAsync(InboundFrame frame, CancellationToken cancellationToken)
134134
{
135135
bool shallReturnPayload = true;
136-
if (frame.Channel == 0)
136+
try
137137
{
138-
if (frame.Type == FrameType.FrameHeartbeat)
138+
if (frame.Channel == 0)
139139
{
140-
// Ignore it: we've already recently reset the heartbeat
140+
if (frame.Type == FrameType.FrameHeartbeat)
141+
{
142+
// Ignore it: we've already recently reset the heartbeat
143+
}
144+
else
145+
{
146+
// In theory, we could get non-connection.close-ok
147+
// frames here while we're quiescing (m_closeReason !=
148+
// null). In practice, there's a limited number of
149+
// things the server can ask of us on channel 0 -
150+
// essentially, just connection.close. That, combined
151+
// with the restrictions on pipelining, mean that
152+
// we're OK here to handle channel 0 traffic in a
153+
// quiescing situation, even though technically we
154+
// should be ignoring everything except
155+
// connection.close-ok.
156+
shallReturnPayload = await _session0.HandleFrameAsync(frame, cancellationToken)
157+
.ConfigureAwait(false);
158+
}
141159
}
142160
else
143161
{
144-
// In theory, we could get non-connection.close-ok
145-
// frames here while we're quiescing (m_closeReason !=
146-
// null). In practice, there's a limited number of
147-
// things the server can ask of us on channel 0 -
148-
// essentially, just connection.close. That, combined
149-
// with the restrictions on pipelining, mean that
150-
// we're OK here to handle channel 0 traffic in a
151-
// quiescing situation, even though technically we
152-
// should be ignoring everything except
153-
// connection.close-ok.
154-
shallReturnPayload = await _session0.HandleFrameAsync(frame, cancellationToken)
155-
.ConfigureAwait(false);
162+
// If we're still m_running, but have a m_closeReason,
163+
// then we must be quiescing, which means any inbound
164+
// frames for non-zero channels (and any inbound
165+
// commands on channel zero that aren't
166+
// Connection.CloseOk) must be discarded.
167+
if (_closeReason is null)
168+
{
169+
// No close reason, not quiescing the
170+
// connection. Handle the frame. (Of course, the
171+
// Session itself may be quiescing this particular
172+
// channel, but that's none of our concern.)
173+
ISession session = _sessionManager.Lookup(frame.Channel);
174+
shallReturnPayload = await session.HandleFrameAsync(frame, cancellationToken)
175+
.ConfigureAwait(false);
176+
}
156177
}
157178
}
158-
else
179+
finally
159180
{
160-
// If we're still m_running, but have a m_closeReason,
161-
// then we must be quiescing, which means any inbound
162-
// frames for non-zero channels (and any inbound
163-
// commands on channel zero that aren't
164-
// Connection.CloseOk) must be discarded.
165-
if (_closeReason is null)
181+
if (shallReturnPayload)
166182
{
167-
// No close reason, not quiescing the
168-
// connection. Handle the frame. (Of course, the
169-
// Session itself may be quiescing this particular
170-
// channel, but that's none of our concern.)
171-
ISession session = _sessionManager.Lookup(frame.Channel);
172-
shallReturnPayload = await session.HandleFrameAsync(frame, cancellationToken)
173-
.ConfigureAwait(false);
183+
frame.ReturnPayload();
174184
}
175185
}
176-
177-
if (shallReturnPayload)
178-
{
179-
frame.ReturnPayload();
180-
}
181186
}
182187

183188
///<remarks>

0 commit comments

Comments
 (0)