Alanxtl commented on code in PR #3826:
URL: https://github.com/apache/dubbo-go/pull/3826#discussion_r4582572009
##########
remoting/getty/getty_server.go:
##########
@@ -137,6 +145,9 @@ type Server struct {
// NewServer create a new Server
func NewServer(url *common.URL, handlers func(*invocation.RPCInvocation)
result.RPCResult) *Server {
+ srvConfLock.Lock()
Review Comment:
NewServer holds the write lock while calling initServer, which runs
yaml.Marshal(protocolConf.Params). Because Params is typed as any, a custom
MarshalYAML implementation can call GetServerConfig() to read defaults. That
call attempts to acquire the same lock and leaves server startup deadlocked. I
reproduced this with a temporary test; the same test passes on the base
revision. Consider serializing the parameters before acquiring the lock, then
applying the configuration and creating the snapshot under the lock.
##########
remoting/getty/getty_server.go:
##########
@@ -225,7 +236,7 @@ func (s *Server) Start() {
serverOpts := []getty.ServerOption{getty.WithLocalAddress(addr)}
if s.conf.SSLEnabled {
serverOpts = append(serverOpts,
getty.WithServerSslEnabled(s.conf.SSLEnabled),
- getty.WithServerTlsConfigBuilder(srvConf.TLSBuilder))
+ getty.WithServerTlsConfigBuilder(s.conf.TLSBuilder))
Review Comment:
ServerConfig is copied shallowly, and TLSBuilder typically contains a
pointer. If a caller retrieves the configuration with GetServerConfig(),
changes a certificate path on the builder, and calls SetServerConfig(), the
change also affects a previously created server. If that server calls Start()
concurrently, the builder access races. I reproduced both the changed
certificate path and the race. Consider isolating the built-in builder when
publishing and returning configurations, and defining an immutability or
concurrency contract for custom builders.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]