From 9ca5ccae32c47fd7298b0f71050a830ecca2c153 Mon Sep 17 00:00:00 2001 From: Russ Magee Date: Tue, 4 Oct 2022 22:30:10 -0700 Subject: [PATCH] (issue #33) use of time.Sleep() prior to ptmx.Close() in xsd.runShellAs() Hack to enable server to complete sending data to client (eg. xs -x "ls /foo" losing end of output) --- xsd/xsd.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/xsd/xsd.go b/xsd/xsd.go index c1bd039..44762a8 100755 --- a/xsd/xsd.go +++ b/xsd/xsd.go @@ -327,6 +327,16 @@ func runShellAs(who, hname, ttype, cmd string, interactive bool, //nolint:funlen // #gv:s/label=\"runShellAs\$1\"/label=\"deferPtmxClose\"/ defer func() { //logger.LogDebug(fmt.Sprintf("[Exited process was %d]", c.Process.Pid)) + + //Ensure socket has sent all data to client prior to closing + //NOTE: This is not ideal, as it would be better to somehow + //determine if there is any pending outgoing (write) data to the + //underlying socket (TCP/KCP) prior to closing; however Go's net pkg + //completely hides lower-level stuff. net.Conn.Close() according to + //docs sends written data in the background, so how best to determine + //all data has been sent? -rlm 2022-10-04 + + time.Sleep(100 * time.Millisecond) //Empirically determined :^/ _ = ptmx.Close() }()