Skip to content

Commit d6295a6

Browse files
phil-halleyprogrium
authored andcommitted
Move channelHandlers to avoid data race (#59)
1 parent 47df570 commit d6295a6

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

server.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ func (srv *Server) ensureHostSigner() error {
5656
}
5757

5858
func (srv *Server) config(ctx Context) *gossh.ServerConfig {
59-
srv.channelHandlers = map[string]channelHandler{
60-
"session": sessionHandler,
61-
"direct-tcpip": directTcpipHandler,
62-
}
6359
config := &gossh.ServerConfig{}
6460
for _, signer := range srv.HostSigners {
6561
config.AddHostKey(signer)
@@ -164,6 +160,12 @@ func (srv *Server) Serve(l net.Listener) error {
164160
if srv.Handler == nil {
165161
srv.Handler = DefaultHandler
166162
}
163+
if srv.channelHandlers == nil {
164+
srv.channelHandlers = map[string]channelHandler{
165+
"session": sessionHandler,
166+
"direct-tcpip": directTcpipHandler,
167+
}
168+
}
167169
var tempDelay time.Duration
168170

169171
srv.trackListener(l, true)

session_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ func (srv *Server) serveOnce(l net.Listener) error {
1818
if e != nil {
1919
return e
2020
}
21+
srv.channelHandlers = map[string]channelHandler{
22+
"session": sessionHandler,
23+
"direct-tcpip": directTcpipHandler,
24+
}
2125
srv.handleConn(conn)
2226
return nil
2327
}

0 commit comments

Comments
 (0)