Skip to content

Commit 0674310

Browse files
author
Julien
committed
fix(sdk): Game runner now waits for AIs to flush their STDERR before reading final error
1 parent 453d2ff commit 0674310

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

runner/src/main/java/com/codingame/gameengine/runner/GameRunner.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,24 @@ private String getNextPlayerOutput(NextPlayerInfo nextPlayerInfo, String nextPla
270270
String playerOutput = player.getOutput(nextPlayerInfo.nbLinesNextOutput, nextPlayerInfo.timeout);
271271
if (playerOutput != null)
272272
playerOutput = playerOutput.replace('\r', '\n');
273-
readError(player);
274273

275-
if (checkOutput(playerOutput, nextPlayerInfo.nbLinesNextOutput) != OutputResult.OK) {
274+
boolean outputCheckOk = checkOutput(playerOutput, nextPlayerInfo.nbLinesNextOutput) == OutputResult.OK;
275+
276+
if (outputCheckOk) {
277+
// Read this turns stderr
278+
readError(player);
279+
} else {
280+
// Give the agent time to crash cleanly
281+
try {
282+
Thread.sleep(nextPlayerInfo.timeout);
283+
} catch (InterruptedException e) {
284+
e.printStackTrace();
285+
}
286+
// Read this turns stderr and crash output
287+
readError(player);
288+
}
289+
290+
if (!outputCheckOk) {
276291
return null;
277292
}
278293
if ((playerOutput != null) && playerOutput.isEmpty() && (nextPlayerInfo.nbLinesNextOutput == 1)) {

0 commit comments

Comments
 (0)