Skip to content

Commit

Permalink
Fix potential instability in iotedged after UploadSupportBundle fails (
Browse files Browse the repository at this point in the history
…#4942)

Upload a support bundle from the portal, using UploadSupportBundle, causes the edge device to stop responding to iotedge list and other commands executed from the cli; in addition, the portal returns a 500 error when the user tries to deploy a new module to the device.
  • Loading branch information
pmzara committed May 19, 2021
1 parent 5e6c47b commit 5e3b60f
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions edge-modules/iotedge-diagnostics-dotnet/src/GetSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,40 @@ public static string GetSocketResponse(string server, string endpoint)
string request = $"GET {endpoint} HTTP/1.1\r\nHost: {server}\r\nConnection: Close\r\n\r\n";
byte[] bytesSent = Encoding.ASCII.GetBytes(request);
byte[] bytesReceived = new byte[256];
string page = string.Empty;

// Create a socket connection with the specified server and port.
using (Socket socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.IP))
{
socket.Connect(new UnixDomainSocketEndPoint(uri.LocalPath));
try
{
socket.ReceiveTimeout = 5000;
socket.SendTimeout = 1000;

socket.Connect(new UnixDomainSocketEndPoint(uri.LocalPath));

// Send request to the server.
socket.Send(bytesSent, bytesSent.Length, 0);
int bytes = 0;

// Send request to the server.
socket.Send(bytesSent, bytesSent.Length, 0);
int bytes = 0;
string page = string.Empty;
do
do
{
bytes = socket.Receive(bytesReceived, bytesReceived.Length, 0);
page = page + Encoding.ASCII.GetString(bytesReceived, 0, bytes);
}
while (bytes > 0);
}
catch (SocketException e)
{
Console.Error.WriteLine(string.Format("SocketError - SocketErrorCode ({0}) : {1}", e.SocketErrorCode, e.Message));
}
catch (Exception e)
{
bytes = socket.Receive(bytesReceived, bytesReceived.Length, 0);
page = page + Encoding.ASCII.GetString(bytesReceived, 0, bytes);
Console.Error.WriteLine(e.Message);
}
while (bytes > 0);

return page;
}
}
}
}
}

0 comments on commit 5e3b60f

Please sign in to comment.