Repository: go
Issue: x/crypto: SSH swallows first character in second connection
Labels: NeedsInvestigation

<!--
Please answer these questions before submitting your issue. Thanks!
For questions please use one of our forums: https://github.com/golang/go/wiki/Questions
-->

### What version of Go are you using (`go version`)?

<pre>
$ go version
go version go1.15 linux/amd64
</pre>

### Does this issue reproduce with the latest release?
Yes.


### What operating system and processor architecture are you using (`go env`)?

<details><summary><code>go env</code> Output</summary><br><pre>
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/usr/local/google/home/jkohen/.cache/go-build"
GOENV="/usr/local/google/home/jkohen/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/usr/local/google/home/jkohen/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/usr/local/google/home/jkohen/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/google-golang"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/google-golang/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build079540723=/tmp/go-build -gno-record-gcc-switches"
</pre></details>

### What did you do?

<!--
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
-->

The following assumes a ssh server in localhost set up with SSH_AUTH_SOCK, which is what my environment provides. It should be trivial for you all to adjust it for a different host and hardcoded password as needed:
1. go run [xcrypto-bug.txt](https://github.com/golang/go/files/5224401/xcrypto-bug.txt)
1. Once you see the "type something" prompt, enter a string and press enter. Note the output.
1. Repeat for the second attempt.

### What did you expect to see?
The output from the second session is exactly what I entered on the keyboard.


### What did you see instead?
The output from the second session is missing the first character. If I add more executions of runTest(), I see the same effect in all but the first session.

For instance, in the session below I typed "hi" both times, but the second time only the "i" was registered:
```
Type something: hi
0000000   h   i  nl
         68  69  0a
0000003
Type something: i
0000000   i  nl
         69  0a
0000002
```

I tried a few things to no avail:
- Discard bytes from stdin before and after the session (with bufio.NewReader().Discard()).
- Different `TerminalMode` settings.
- Calling `os.Stdin.Sync()` and `os.Stdin.Seek(0, 2)`
- Execute reset locally before the SSH session.
- etc.

I also tried a couple different versions of the SSH code in the snippet, and always got the same result. I was unable to reproduce this with a local shell, or with the ssh command-line tool (OpenSSH).