From 15a0fd3b0c442eec42644e93c3fdbb7eedb05db5 Mon Sep 17 00:00:00 2001 From: Bogdan Popa Date: Tue, 24 Sep 2019 20:33:26 +0300 Subject: [PATCH] formation: ensure ports are fully drained before exiting --- chief/private/formation.rkt | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/chief/private/formation.rkt b/chief/private/formation.rkt index 90e5941..df79d1e 100644 --- a/chief/private/formation.rkt +++ b/chief/private/formation.rkt @@ -107,11 +107,18 @@ (lambda _ (emit 'message (format "process started with pid ~a" pid))) (lambda _ - (let loop () - (define line (read-line (sync (choice-evt stdout stderr)))) - (unless (eof-object? line) - (emit 'message line) - (loop)))) + (let loop ([ports (list stdout stderr)]) + (define port (sync (apply choice-evt ports))) + (define line (read-line port)) + (cond + [(eof-object? line) + (define ports* (remq port ports)) + (unless (null? ports*) + (loop ports*))] + + [else + (emit 'message line) + (loop ports)]))) (lambda _ (emit 'exit (control 'exit-code))))))