Skip to content

Commit

Permalink
Move channelHandlers to avoid data race (gliderlabs#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-halley authored and moul committed Nov 16, 2018
1 parent ae3cdb7 commit 41e58b6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 6 additions & 4 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ func (srv *Server) ensureHostSigner() error {
}

func (srv *Server) config(ctx Context) *gossh.ServerConfig {
srv.channelHandlers = map[string]channelHandler{
"session": sessionHandler,
"direct-tcpip": directTcpipHandler,
}
config := &gossh.ServerConfig{}
for _, signer := range srv.HostSigners {
config.AddHostKey(signer)
Expand Down Expand Up @@ -164,6 +160,12 @@ func (srv *Server) Serve(l net.Listener) error {
if srv.Handler == nil {
srv.Handler = DefaultHandler
}
if srv.channelHandlers == nil {
srv.channelHandlers = map[string]channelHandler{
"session": sessionHandler,
"direct-tcpip": directTcpipHandler,
}
}
var tempDelay time.Duration

srv.trackListener(l, true)
Expand Down
4 changes: 4 additions & 0 deletions session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ func (srv *Server) serveOnce(l net.Listener) error {
if e != nil {
return e
}
srv.channelHandlers = map[string]channelHandler{
"session": sessionHandler,
"direct-tcpip": directTcpipHandler,
}
srv.handleConn(conn)
return nil
}
Expand Down

0 comments on commit 41e58b6

Please sign in to comment.