riju icon indicating copy to clipboard operation
riju copied to clipboard

REPL output sometimes cuts off/drops early

Open kwshi opened this issue 2 years ago • 1 comments

Sometimes, the REPL doesn't print output that it's supposed to print, and the program prematurely ends before all output has been sent. Example-- the following program prints 0 through 9; when this program is run, most of the times the correct output is shown but sometimes, seemingly at random, the output cuts off early:

image

Inspecting the websocket message log shows the following exchange:

  • (up) {"event":"runCode","code":"#include <iostream>\n\nint main() {\n for (int i = 0; i < 10; ++i) {\n std::cout << i << std::endl;\n }\n}\n"}
  • (down) {"event":"terminalClear"}
  • (down) {"event":"terminalOutput","output":"0\r\n1\r\n2\r\n3\r\n"}
  • (down) {"event":"serviceFailed","service":"terminal","error":"Exited with status 0","code":0}
  • (down) {"event":"terminalInput","input":"\r"}

So it seems like the missing output is not transmitted at all by the server, rather than it being hidden by some UI-level bug.

(Another example, in which the last output line hello is dropped:) image

  • (up) {"event":"runCode","code":"#include <iostream>\n\nint main() {\n for (int i = 0; i < 5; ++i) {\n std::cout << i << std::endl;\n }\n\n int n;\n std::cin >> n;\n\n std::cout << \"hello \" << n << std::endl;\n}\n"}
  • (down) {"event":"terminalClear"}
  • (down) {"event":"terminalOutput","output":"0\r\n1\r\n2\r\n3\r\n4\r\n"}
  • (up) {"event":"terminalInput","input":"7"}
  • (down) {"event":"terminalOutput","output":"7"}
  • (down) (down) {"event":"serviceFailed","service":"terminal","error":"Exited with status 0","code":0}

kwshi avatar Sep 29 '22 22:09 kwshi

Huh, that's very odd, I'm not sure what could be causing this. The process management code needs a serious rewrite, I suspect it has a number of potential race conditions because I wrote my own thing instead of using an existing container runtime like Kubernetes.

raxod502 avatar Oct 05 '22 23:10 raxod502