Skip to content

Commit

Permalink
Make more robust in face of random other stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobbotsch committed Nov 2, 2022
1 parent 43d518a commit 99360ba
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Fuzzlyn.ExecutionServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ public static void Main(string[] args)
return;
}
// This identifier must be in sync with
// RunningExecutionServer.RequestAndReceive.
Console.Write("@!EXEC_SERVER_RESPONSE!@");
Console.WriteLine(JsonSerializer.Serialize(resp));
if (req.Kind == RequestKind.Shutdown)
return;
Expand Down
33 changes: 28 additions & 5 deletions Fuzzlyn/RunningExecutionServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,31 @@ private ReceiveResult RequestAndReceive(Request req, TimeSpan timeout)
{
using var cts = new CancellationTokenSource(timeout);
using var reg = cts.Token.Register(() => { killed = true; Kill(); });
line = _process.StandardOutput.ReadLine();
bool first = true;
while (true)
{
line = _process.StandardOutput.ReadLine();

if (line == null)
{
break;
}

if (line.StartsWith("@!EXEC_SERVER_RESPONSE!@"))
{
line = line["@!EXEC_SERVER_RESPONSE!@".Length..];
break;
}

if (first)
{
Console.WriteLine("Received unexpected output from execution server:");
}

Console.WriteLine(line);

first = false;
}
}

LastUseTimer.Restart();
Expand All @@ -43,20 +67,19 @@ private ReceiveResult RequestAndReceive(Request req, TimeSpan timeout)
return new ReceiveResult { Ended = true, Stderr = stderr };
}

Response resp;
try
{
resp = JsonSerializer.Deserialize<Response>(line);
Response resp = JsonSerializer.Deserialize<Response>(line);
return new ReceiveResult { Response = resp };
}
catch (JsonException ex)
{
Console.WriteLine("Received malformed JSON response");
Console.WriteLine("Could not parse JSON response");
Console.WriteLine(ex.ToString());
Console.WriteLine(line);
return new ReceiveResult { Ended = true, Stderr = "Malformed result" };
}

return new ReceiveResult { Response = JsonSerializer.Deserialize<Response>(line) };
}

public RunSeparatelyResults RunPair(ProgramPair pair, TimeSpan timeout)
Expand Down

0 comments on commit 99360ba

Please sign in to comment.