mirror of
https://github.com/project-zot/zot.git
synced 2026-06-19 22:27:58 +08:00
fix: address code review comments (#3942)
* fix: address code review comments in https://github.com/project-zot/zot/pull/3885#pullrequestreview-4045836197 Signed-off-by: Andrei Aaron <andreifdaaron@gmail.com> * fix: data race in GetPort() See https://github.com/project-zot/zot/actions/runs/24045271222/job/70126983674?pr=3942 Signed-off-by: Andrei Aaron <andreifdaaron@gmail.com> * fix(test): reuse ReadLogFileAndSearchString for auto-port log; throttle poll loop Signed-off-by: Andrei Aaron <andreifdaaron@gmail.com> --------- Signed-off-by: Andrei Aaron <andreifdaaron@gmail.com>
This commit is contained in:
+14
-16
@@ -57,8 +57,8 @@ type Controller struct {
|
||||
LDAPClient *LDAPClient
|
||||
taskScheduler *scheduler.Scheduler
|
||||
Healthz *common.Healthz
|
||||
// runtime params
|
||||
chosenPort int // kernel-chosen port
|
||||
// runtime params (atomic: Run may set the port concurrently with GetPort readers, e.g. tests)
|
||||
chosenPort atomic.Int64
|
||||
// TLS certificate management
|
||||
TlsWatcher atomic.Pointer[TlsConfigWatcher]
|
||||
}
|
||||
@@ -127,7 +127,7 @@ func NewController(appConfig *config.Config) *Controller {
|
||||
}
|
||||
|
||||
func (c *Controller) GetPort() int {
|
||||
return c.chosenPort
|
||||
return int(c.chosenPort.Load())
|
||||
}
|
||||
|
||||
func (c *Controller) Run() error {
|
||||
@@ -186,23 +186,21 @@ func (c *Controller) Run() error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Always derive the bound port from the listener so GetPort matches the actual socket (numeric
|
||||
// config, kernel-chosen :0, or service names like "http" resolved by net.Listen).
|
||||
chosenAddr, ok := listener.Addr().(*net.TCPAddr)
|
||||
if !ok {
|
||||
c.Log.Error().Str("port", port).Msg("invalid addr type")
|
||||
|
||||
return errors.ErrBadType
|
||||
}
|
||||
|
||||
c.chosenPort.Store(int64(chosenAddr.Port))
|
||||
|
||||
if port == "0" || port == "" {
|
||||
chosenAddr, ok := listener.Addr().(*net.TCPAddr)
|
||||
if !ok {
|
||||
c.Log.Error().Str("port", port).Msg("invalid addr type")
|
||||
|
||||
return errors.ErrBadType
|
||||
}
|
||||
|
||||
c.chosenPort = chosenAddr.Port
|
||||
|
||||
c.Log.Info().Int("port", chosenAddr.Port).IPAddr("address", chosenAddr.IP).Msg(
|
||||
"port is unspecified, listening on kernel chosen port",
|
||||
)
|
||||
} else {
|
||||
chosenPort, _ := strconv.ParseInt(port, 10, 32)
|
||||
|
||||
c.chosenPort = int(chosenPort)
|
||||
}
|
||||
|
||||
tlsConfig := c.Config.CopyTLSConfig()
|
||||
|
||||
Reference in New Issue
Block a user