Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/crypto/ssh: Session.Wait() hangs while reading from msg channel after sending EOF to os.Stdin #6088

Closed
gopherbot opened this issue Aug 9, 2013 · 13 comments
Milestone

Comments

@gopherbot
Copy link

@gopherbot gopherbot commented Aug 9, 2013

by mischief@offblast.org:

Hi, I'm using go.crypto/ssh to implement an ssh client. I connected
os.Stdin/Stdout/Stderr to Sesion.Stdin/Stdout/Stderr, allocated a PTY and started a
shell. Sending EOF to stdin will cause Session.Wait() to never return while waiting for
a message or close() on clientChan.msg.

The expected behavior here would be for go.crypto/ssh to catch the EOF from
Session.Stdin, send an eof to the remote side's program. Currently, it seems to just
kill Stdin locally and hang it. It might be that the remote program is not a shell, and
some program like cat. In that case, an EOF would simply stop the remote cat process. If
it were the shell, the shell would quit, and send a channel close message back to
go.crypto/ssh, indicating the session is done.

My program can be seen here:
https://bitbucket.org/mischief/scpu/src/51d57a77fcb4799b99424aac782f4ba061b1df01/scpu.go?at=default

I'm using go tip, and I'm testing this on debian 7 and 9front hosts, and connecting to
an openbsd 5.3 server.

Incriminating backtrace after sending EOF:

gdb$ goroutine 1 bt                                                                     
                                                                                 
#0  0x0000000000417a06 in runtime.park (unlockf=void, lock=void, reason=void) at
/srv/go/src/pkg/runtime/proc.c:1224
#1  0x00000000004055f3 in runtime.chanrecv (c=void, ep=void, selected=void,
received=void) at /srv/go/src/pkg/runtime/chan.c:391
#2  0x0000000000405a75 in runtime.chanrecv2 (t=void, c=void) at
/srv/go/src/pkg/runtime/chan.c:464
#3  0x0000000000432b76 in code.google.com/p/go.crypto/ssh.(*Session).wait
(s=0xc210036770, ~anon0=...) at
/tmp/scpu/src/code.google.com/p/go.crypto/ssh/session.go:415
#4  0x0000000000432a23 in code.google.com/p/go.crypto/ssh.(*Session).Wait
(s=0xc210036770, ~anon0=...) at
/tmp/scpu/src/code.google.com/p/go.crypto/ssh/session.go:397
#5  0x000000000040187c in main.interactive (session=0xc210036770, ~anon1=...) at
/tmp/scpu/src/bitbucket.org/mischief/scpu/scpu.go:99
#6  0x000000000040145a in main.main () at
/tmp/scpu/src/bitbucket.org/mischief/scpu/scpu.go:74
#7  0x0000000000415954 in runtime.main () at /srv/go/src/pkg/runtime/proc.c:182
#8  0x0000000000417bd0 in ?? () at /srv/go/src/pkg/runtime/proc.c:1267
#9  0x0000000000000000 in ?? ()
@robpike
Copy link
Contributor

@robpike robpike commented Aug 10, 2013

Comment 1:

Labels changed: added priority-later, removed priority-triage, go1.2maybe.

@robpike
Copy link
Contributor

@robpike robpike commented Aug 10, 2013

Comment 2:

Status changed to Accepted.

@hanwen
Copy link
Contributor

@hanwen hanwen commented Oct 26, 2013

Comment 3:

Do you have a self contained example that demonstrates this? in ssh/test/ there is a
framework for writing tests against OpenSSH. I think I have a change that might fix
this, but I'd like to verify.
@hanwen
Copy link
Contributor

@hanwen hanwen commented Oct 26, 2013

Comment 4:

Do you have a self contained example that demonstrates this? in ssh/test/ there is a
framework for writing tests against OpenSSH. I think I have a change that might fix
this, but I'd like to verify.
@rsc
Copy link
Contributor

@rsc rsc commented Nov 27, 2013

Comment 5:

Labels changed: added go1.3maybe.

@rsc
Copy link
Contributor

@rsc rsc commented Dec 4, 2013

Comment 6:

Labels changed: added release-none, removed go1.3maybe.

@rsc
Copy link
Contributor

@rsc rsc commented Dec 4, 2013

Comment 7:

Labels changed: added repo-crypto.

@axw
Copy link
Contributor

@axw axw commented Dec 24, 2013

Comment 8:

I've just hit this. Repro test case (add to session_test.go, along with import "os"):
http://play.golang.org/p/ENRws4aHYV
After the exec completes, Wait blocks until each stdio goroutine returns. The io.Copy
from the pipe is blocking indefinitely.
@davecheney
Copy link
Contributor

@davecheney davecheney commented Dec 24, 2013

Comment 9:

@axwalk, could you please try the development fork at code.google.com/p/gosshnew/ssh and
see if the problem is fixed there ?
@axw
Copy link
Contributor

@axw axw commented Dec 24, 2013

Comment 10:

@davecheney, same deal on gosshnew.
@davecheney
Copy link
Contributor

@davecheney davecheney commented Dec 24, 2013

Comment 11:

@axwalk, thanks for confirming.
@axw
Copy link
Contributor

@axw axw commented Dec 24, 2013

Comment 12:

https://golang.org/cl/45200043/
(Is there a way to automatically link CLs to issues?)
@mikioh mikioh changed the title go.crypto/ssh: Session.Wait() hangs while reading from msg channel after sending EOF to os.Stdin ssh: Session.Wait() hangs while reading from msg channel after sending EOF to os.Stdin Jan 7, 2015
@rsc rsc added this to the Unplanned milestone Apr 10, 2015
@rsc rsc changed the title ssh: Session.Wait() hangs while reading from msg channel after sending EOF to os.Stdin x/crypto/ssh: Session.Wait() hangs while reading from msg channel after sending EOF to os.Stdin Apr 14, 2015
@rsc rsc modified the milestones: Unreleased, Unplanned Apr 14, 2015
@rsc rsc removed the repo-crypto label Apr 14, 2015
@hanwen
Copy link
Contributor

@hanwen hanwen commented Aug 12, 2015

@hanwen hanwen closed this Aug 18, 2015
@golang golang locked and limited conversation to collaborators Aug 22, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants
You can’t perform that action at this time.