main ← tgxworld/refresh-site-settings-after-fork
merged 02:31AM - 22 Jul 26 UTC
Discourse keeps site settings in memory so it does not need to read them from th…e database for every request or job.
Pitchfork starts Sidekiq from a long-running parent process. That parent can still have the site settings that were loaded when Discourse first started. When an admin changes a setting, the running Sidekiq process gets the new value through MessageBus, but the parent can keep the old value.
If Sidekiq is later restarted, the new Sidekiq process copies the old settings from its parent. For example, after changing `site_contact_username`, a restarted Sidekiq process could send system messages from the previous account. The wrong value remained in use until another setting changed or Discourse was restarted.
This change reloads site settings from the database after Discourse starts a new process. It starts listening for new setting changes before the reload, so a change made during startup is not missed. On multisite installations, it reloads each site separately.
The reload only updates memory in the new process. It does not clear shared caches or send another MessageBus message, which avoids extra work when several processes restart at the same time.
Reported at https://meta.discourse.org/t/site-settings-are-stale-in-sidekiq-after-it-re-forks/408094