diff --git a/server/channels/app/server.go b/server/channels/app/server.go index 6197c6c55be..65c3dbf371e 100644 --- a/server/channels/app/server.go +++ b/server/channels/app/server.go @@ -260,8 +260,17 @@ func NewServer(options ...Option) (*Server, error) { product.CommandKey: app, } - // Step 4: Initialize products. - // Depends on s.httpService. + // It is important to initialize the hub only after the global logger is set + // to avoid race conditions while logging from inside the hub. + // Step 4: Start platform + s.platform.Start() + + // NOTE: There should be no call to App.Srv().Channels() before step 5 is done + // otherwise it will throw a panic. + + // Step 5: Initialize products. + // Depends on s.httpService, and depends on the hub to be initialized. + // Otherwise we run into race conditions. err = s.initializeProducts(product.GetProducts(), serviceMap) if err != nil { return nil, errors.Wrap(err, "failed to initialize products") @@ -275,11 +284,6 @@ func NewServer(options ...Option) (*Server, error) { } app.ch = channelsWrapper.app.ch - // It is important to initialize the hub only after the global logger is set - // to avoid race conditions while logging from inside the hub. - // Step 5: Start hub in platform which the hub depends on s.Channels() (step 4) - s.platform.Start() - // ------------------------------------------------------------------------- // Everything below this is not order sensitive and safe to be moved around. // If you are adding a new field that is non-channels specific, please add