[android] deliver both output streams before OnClose

This commit is contained in:
Zoltán Papp
2026-08-12 12:45:32 +02:00
parent a98ced399e
commit ba16475ad6
+13 -7
View File
@@ -307,8 +307,16 @@ func (s *SSHClient) startSession(cols, rows int) error {
s.stdin = stdin s.stdin = stdin
s.mu.Unlock() s.mu.Unlock()
go s.readLoop(stdout, "stdout") readerDone := make(chan string, 2)
go s.readLoop(stderr, "stderr") go func() { readerDone <- s.readLoop(stdout, "stdout") }()
go func() { readerDone <- s.readLoop(stderr, "stderr") }()
go func() {
reason := <-readerDone
if second := <-readerDone; reason == "" {
reason = second
}
s.notifyClose(reason)
}()
log.Debug("SSH: session started, shell running") log.Debug("SSH: session started, shell running")
return nil return nil
} }
@@ -593,7 +601,7 @@ func (s *SSHClient) dialAndHandshake(host string, port int, clientConfig *gossh.
return nil return nil
} }
func (s *SSHClient) readLoop(r io.Reader, name string) { func (s *SSHClient) readLoop(r io.Reader, name string) string {
buf := make([]byte, 4096) buf := make([]byte, 4096)
for { for {
n, err := r.Read(buf) n, err := r.Read(buf)
@@ -610,12 +618,10 @@ func (s *SSHClient) readLoop(r io.Reader, name string) {
if err != nil { if err != nil {
// EOF is a normal shell exit, so report it without a reason. // EOF is a normal shell exit, so report it without a reason.
if errors.Is(err, io.EOF) { if errors.Is(err, io.EOF) {
s.notifyClose("") return ""
return
} }
log.Debugf("ssh %s read: %v", name, err) log.Debugf("ssh %s read: %v", name, err)
s.notifyClose(rootCause(err).Error()) return rootCause(err).Error()
return
} }
} }
} }