我很少在 Stack Overflow 上提问,但这次我却陷入了困境。
TLDR我需要知道它channel.Close()
是如何golang.org/x/crypto/ssh
工作的以及我应该在哪里调用它(假设这是我需要的)。
我正在编写一个“小”程序来自动同步我的 Git 存储库,包括存储、额外文件等。我使用go-ssh来处理服务器上最重要的部分。该项目的当前状态可以在 GitHub 上找到
我试图将其缩小到一个简单的示例。这是我从Golang 存储库中的官方示例中调整的少数内容之一。我删除了terminal
引用,并使其明确处理(随机)命令:
go func(in <-chan *ssh.Request) {
for req := range in {
switch req.Type {
case "exec":
channel.Stderr().Write([]byte("Request received!\n"))
req.Reply(true, nil)
// Do some more work here
channel.Close() // ???
default:
req.Reply(false, nil)
}
}
wg.Done()
}(requests)
每当我尝试连接类似ssh localhost -T -vvvv -p 2022 git-receive-pack foo
示例的内容时,我都会得到以下信息:
Authenticated to localhost ([::1]:2022) using "publickey".
debug1: channel 0: new session [client-session] (inactive timeout: 0)
debug3: ssh_session2_open: channel_new: 0
debug2: channel 0: send open
debug3: send packet: type 90
debug1: Entering interactive session.
debug1: pledge: filesystem
debug3: client_repledge: enter
debug3: receive packet: type 91
debug2: channel_input_open_confirmation: channel 0: callback start
debug2: fd 3 setting TCP_NODELAY
debug3: set_sock_tos: set socket 3 IPV6_TCLASS 0x20
debug2: client_session2_setup: id 0
debug1: Sending command: git-receive-pack foo
debug2: channel 0: request exec confirm 1
debug3: send packet: type 98
debug3: client_repledge: enter
debug2: channel_input_open_confirmation: channel 0: callback done
debug2: channel 0: open confirm rwindow 2097152 rmax 32768
debug2: channel 0: rcvd ext data 6
debug3: receive packet: type 99
debug2: channel_input_status_confirm: type 99 id 0
debug2: exec request accepted on channel 0
debug3: receive packet: type 97
debug2: channel 0: rcvd close
debug2: channel 0: output open -> drain
debug2: chan_shutdown_read: channel 0: (i0 o1 sock -1 wfd 4 efd 6 [write])
debug2: channel 0: input open -> closed
debug3: channel 0: will not send data after close
debug2: channel 0: obuf_empty delayed efd 6/(6)
Request received!
debug2: channel 0: written 6 to efd 6
debug3: channel 0: will not send data after close
debug2: channel 0: obuf empty
debug2: chan_shutdown_write: channel 0: (i3 o1 sock -1 wfd 5 efd 6 [write])
debug2: channel 0: output drain -> closed
debug2: channel 0: almost dead
debug2: channel 0: gc: notify user
debug2: channel 0: gc: user detached
debug2: channel 0: send_close2
debug2: channel 0: send close for remote id 0
debug3: send packet: type 97
debug2: channel 0: is dead
debug2: channel 0: garbage collecting
debug1: channel 0: free: client-session, nchannels 1
debug3: channel 0: status: The following connections are open:
#0 client-session (t4 [session] r0 nm0 i3/0 o3/0 e[write]/0 fd -1/-1/6 sock -1 cc -1 nc0 io 0x00/0x00)
debug3: send packet: type 1
Transferred: sent 3624, received 2892 bytes, in 0.0 seconds
Bytes per second: sent 3203530.2, received 2556459.6
debug1: Exit status -1
在我的个人项目中,也会出现“破管”的情况。
有谁知道如何解决这个问题?