Skip to content

Modern Docker Management, Designed for Everyone

fix: data race on initial loading of settings/users

Kyle Mendell80a9bef0da4c
diff --git a/backend/.air.toml b/backend/.air.toml
index 7115d0253..a07234de9 100644
--- a/backend/.air.toml
+++ b/backend/.air.toml
@@ -3,7 +3,7 @@ tmp_dir = ".bin"
[build]
bin = "./.bin/arcane"
- cmd = "CGO_ENABLED=0 go build -tags 'exclude_frontend' -ldflags='-buildid=' -o ./.bin/arcane ./cmd"
+ cmd = "CGO_ENABLED=1 go build -tags 'exclude_frontend' -ldflags='-buildid=' -o ./.bin/arcane ./cmd"
exclude_dir = [".bin", "data", "node_modules", ".git"]
stop_on_error = true
delay = 500
diff --git a/frontend/src/lib/services/api-service.ts b/frontend/src/lib/services/api-service.ts
index a8c3cc88d..eb7b8b8d4 100644
--- a/frontend/src/lib/services/api-service.ts
+++ b/frontend/src/lib/services/api-service.ts
@@ -37,7 +37,6 @@ abstract class BaseAPIService {
this.api.interceptors.response.use(
(response) => response,
async (error) => {
- console.log(error);
const status = error?.response?.status;
const originalRequest = error.config;
@@ -72,6 +71,7 @@ abstract class BaseAPIService {
'/auth/oidc',
'/auth/oidc/login',
'/auth/oidc/callback',
+ '/auth/me',
'/settings/public'
];
const isAuthApi = skipAuthPaths.some((p) => reqUrl.startsWith(p));
diff --git a/frontend/src/lib/services/settings-service.ts b/frontend/src/lib/services/settings-service.ts
index a46a14c38..254d247a7 100644
--- a/frontend/src/lib/services/settings-service.ts
+++ b/frontend/src/lib/services/settings-service.ts
@@ -7,6 +7,8 @@ type KeyValuePair = { key: string; value: string };
export default class SettingsService extends BaseAPIService {
async getSettings(): Promise<Settings> {
+ // Wait for environment store to be initialized before fetching settings
+ await environmentStore.ready;
const envId = await environmentStore.getCurrentEnvironmentId();
// If we're on environment 0, just get all settings normally
@@ -46,6 +48,8 @@ export default class SettingsService extends BaseAPIService {
}
async updateSettings(settings: Partial<Settings>) {
+ // Wait for environment store to be initialized before updating settings
+ await environmentStore.ready;
const envId = await environmentStore.getCurrentEnvironmentId();
const uiSettings: Record<string, any> = {};
diff --git a/frontend/src/routes/+layout.ts b/frontend/src/routes/+layout.ts
index 62862969c..b12381738 100644
--- a/frontend/src/routes/+layout.ts
+++ b/frontend/src/routes/+layout.ts
@@ -12,31 +12,49 @@ import { environmentManagementService } from '$lib/services/env-mgmt-service';
export const ssr = false;
export const load = async () => {
- const settingsPromise = settingsService.getSettings().catch((e) => {
- console.error('Error fetching settings:', e);
- return settingsService.getPublicSettings().catch(() => null);
- });
-
- const environmentRequestOptions: SearchPaginationSortRequest = {
- pagination: {
- page: 1,
- limit: 1000
- }
- };
-
+ // Step 1: Check authentication first
const user = await userService.getCurrentUser().catch(() => null);
+ // Step 2: Only fetch authenticated data if user is logged in
+ let settings = null;
+
if (user) {
+ // Initialize environment store (required for settings service)
+ const environmentRequestOptions: SearchPaginationSortRequest = {
+ pagination: {
+ page: 1,
+ limit: 1000
+ }
+ };
+
const environments = await tryCatch(environmentManagementService.getEnvironments(environmentRequestOptions));
if (!environments.error) {
await environmentStore.initialize(environments.data.data);
} else {
await environmentStore.initialize([]);
}
+
+ // Fetch settings after environment store is initialized
+ // Settings service depends on environmentStore.getCurrentEnvironmentId()
+ settings = await settingsService.getSettings().catch(() => null);
} else {
+ // Initialize empty environment store for unauthenticated users
await environmentStore.initialize([]);
+
+ // Try to fetch public settings for login page configuration
+ settings = await settingsService.getPublicSettings().catch(() => null);
+ }
+
+ // Step 3: Update stores with fetched data (always, even if null)
+ if (user) {
+ await userStore.setUser(user);
}
+ if (settings) {
+ settingsStore.set(settings);
+ }
+
+ // Step 4: Fetch version information (independent, works for all users)
let versionInformation: AppVersionInformation = {
currentVersion: versionService.getCurrentVersion(),
displayVersion: versionService.getCurrentVersion(),
@@ -65,16 +83,6 @@ export const load = async () => {
};
} catch {}
- const settings = await settingsPromise;
-
- if (user) {
- await userStore.setUser(user);
- }
-
- if (settings) {
- settingsStore.set(settings);
- }
-
return {
user,
settings,