Cleaner fix for issues #22,#33

This commit is contained in:
Russ Magee 2022-10-12 21:27:48 -07:00
parent 9ca5ccae32
commit 5ee09de99a
3 changed files with 14 additions and 16 deletions

View File

@ -1,4 +1,4 @@
VERSION := 0.9.5.2 VERSION := 0.9.5.3
.PHONY: lint vis clean common client server passwd subpkgs install uninstall reinstall .PHONY: lint vis clean common client server passwd subpkgs install uninstall reinstall
## Tag version of binaries with build info wrt. ## Tag version of binaries with build info wrt.

View File

@ -327,16 +327,6 @@ func runShellAs(who, hname, ttype, cmd string, interactive bool, //nolint:funlen
// #gv:s/label=\"runShellAs\$1\"/label=\"deferPtmxClose\"/ // #gv:s/label=\"runShellAs\$1\"/label=\"deferPtmxClose\"/
defer func() { defer func() {
//logger.LogDebug(fmt.Sprintf("[Exited process was %d]", c.Process.Pid)) //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() _ = ptmx.Close()
}() }()
@ -869,9 +859,6 @@ func main() { //nolint:funlen,gocyclo
// Returned hopefully via an EOF or exit/logout; // Returned hopefully via an EOF or exit/logout;
logger.LogNotice(fmt.Sprintf("[s->c copy completed for %s@%s, status %d]\n", rec.Who(), hname, cmdStatus)) //nolint:errcheck logger.LogNotice(fmt.Sprintf("[s->c copy completed for %s@%s, status %d]\n", rec.Who(), hname, cmdStatus)) //nolint:errcheck
} }
// HACK: Bug #22: (xc) Need to wait for rcvr to get final data
// TODO: Await specific msg from client to inform they have gotten all data from the tarpipe
time.Sleep(900 * time.Millisecond) //nolint:gomnd // Let rcvr set this on setup?
// Clear current op so user can enter next, or EOF // Clear current op so user can enter next, or EOF
rec.SetOp([]byte{0}) rec.SetOp([]byte{0})

View File

@ -267,8 +267,6 @@ func _new(kexAlg KEXAlg, conn *net.Conn) (hc *Conn, e error) {
tempMap := make(map[uint16]*TunEndpoint) tempMap := make(map[uint16]*TunEndpoint)
hc.tuns = &tempMap hc.tuns = &tempMap
*hc.closeStat = CSEStillOpen // open or prematurely-closed status
// Set up KEx/KEM-specifics // Set up KEx/KEM-specifics
switch kexAlg { switch kexAlg {
case KEX_HERRADURA256: case KEX_HERRADURA256:
@ -979,6 +977,19 @@ func (hc *Conn) Close() (err error) {
log.Printf("** Writing closeStat %d at Close()\n", *hc.closeStat) log.Printf("** Writing closeStat %d at Close()\n", *hc.closeStat)
//(*hc.c).SetWriteDeadline(time.Now().Add(500 * time.Millisecond)) //(*hc.c).SetWriteDeadline(time.Now().Add(500 * time.Millisecond))
hc.WritePacket(s, CSOExitStatus) hc.WritePacket(s, CSOExitStatus)
// HACK: Bug #22,#33: Need to wait for rcvr to get final data
// TODO: Find a way to explicitly check if any outgoing data is pending
//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(10 * time.Millisecond) //nolint:gomnd
err = (*hc.c).Close() err = (*hc.c).Close()
logger.LogDebug(fmt.Sprintln("[Conn Closing]")) logger.LogDebug(fmt.Sprintln("[Conn Closing]"))
return return