Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly dispose UDS for Workload Client. (#5035) #5044

Merged
merged 5 commits into from
Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,10 @@ public override int Read(byte[] buffer, int offset, int count)
public override void SetLength(long value) => throw new NotImplementedException();

public override void Write(byte[] buffer, int offset, int count) => throw new NotImplementedException();

protected override void Dispose(bool disposing)
{
this.stream.Dispose();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,31 @@ public HttpUdsMessageHandler(Uri providerUri)

protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
Socket socket = await this.GetConnectedSocketAsync();
var stream = new HttpBufferedStream(new NetworkStream(socket, true));

var serializer = new HttpRequestResponseSerializer();
byte[] requestBytes = serializer.SerializeRequest(request);

Events.SendRequest(request.RequestUri);
await stream.WriteAsync(requestBytes, 0, requestBytes.Length, cancellationToken);
if (request.Content != null)
var endpoint = new UnixDomainSocketEndPoint(this.providerUri.LocalPath);
using (Socket socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified))
{
await request.Content.CopyToAsync(stream);
}
Events.Connecting(this.providerUri.LocalPath);
await socket.ConnectAsync(endpoint);
Events.Connected(this.providerUri.LocalPath);

HttpResponseMessage response = await serializer.DeserializeResponse(stream, cancellationToken);
Events.ResponseReceived(response.StatusCode);
using (var stream = new HttpBufferedStream(new NetworkStream(socket, true)))
{
var serializer = new HttpRequestResponseSerializer();
byte[] requestBytes = serializer.SerializeRequest(request);

return response;
}
Events.SendRequest(request.RequestUri);
await stream.WriteAsync(requestBytes, 0, requestBytes.Length, cancellationToken);
if (request.Content != null)
{
await request.Content.CopyToAsync(stream);
}

async Task<Socket> GetConnectedSocketAsync()
{
var endpoint = new UnixDomainSocketEndPoint(this.providerUri.LocalPath);
var socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified);
Events.Connecting(this.providerUri.LocalPath);
await socket.ConnectAsync(endpoint);
Events.Connected(this.providerUri.LocalPath);
HttpResponseMessage response = await serializer.DeserializeResponse(stream, cancellationToken);
Events.ResponseReceived(response.StatusCode);

return socket;
return response;
}
}
}

static class Events
Expand Down