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() }()