in src/Microsoft.Azure.Relay/HybridHttpConnection.cs [136:174]
async Task<RequestCommandAndStream> ReceiveRequestOverRendezvousAsync()
{
using (var cancelSource = new CancellationTokenSource(this.OperationTimeout))
{
// A Rendezvous is required to get full request
await this.EnsureRendezvousAsync(cancelSource.Token).ConfigureAwait(false);
}
RelayEventSource.Log.HybridHttpReadRendezvousValue(this, "request command");
ListenerCommand.RequestCommand requestCommand;
using (var rendezvousCommandStream = new WebSocketMessageStream(this.rendezvousWebSocket, this.OperationTimeout))
{
// Deserializing the object from stream makes a sync-over-async call which can deadlock
// if performed on the websocket transport's callback thread.
requestCommand = await Task.Run(() => ListenerCommand.ReadObject(rendezvousCommandStream).Request).ConfigureAwait(false);
if (rendezvousCommandStream.MessageType == WebSocketMessageType.Close)
{
throw RelayEventSource.Log.ThrowingException(new InvalidOperationException(SR.EntityClosedOrAborted), this);
}
else if (rendezvousCommandStream.MessageType != WebSocketMessageType.Text)
{
throw RelayEventSource.Log.ThrowingException(
new ProtocolViolationException(SR.GetString(SR.InvalidType, WebSocketMessageType.Text, rendezvousCommandStream.MessageType)), this);
}
else if (requestCommand == null)
{
throw RelayEventSource.Log.ThrowingException(new ProtocolViolationException(SR.GetString(SR.InvalidType, "request", "{unknown}")), this);
}
}
Stream requestStream = null;
if (requestCommand.Body.HasValue && requestCommand.Body.Value)
{
RelayEventSource.Log.HybridHttpReadRendezvousValue(this, "request body");
requestStream = new WebSocketMessageStream(this.rendezvousWebSocket, this.OperationTimeout);
}
return new RequestCommandAndStream(requestCommand, requestStream);
}