Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Update mobile app and browser extension server connection timeouts (#2202)
Leendert de Borst6a7546a1c58c
diff --git a/apps/browser-extension/src/entrypoints/popup/hooks/useVaultSync.ts b/apps/browser-extension/src/entrypoints/popup/hooks/useVaultSync.tsindex 2435b23fe..d3275bf21 100644--- a/apps/browser-extension/src/entrypoints/popup/hooks/useVaultSync.ts+++ b/apps/browser-extension/src/entrypoints/popup/hooks/useVaultSync.ts@@ -61,6 +61,18 @@ export const useVaultSync = (): { syncVault: (options?: VaultSyncOptions) => Proreturn false;}+ /*+ * If the lightweight status check already determined the server is unreachable, skip the full+ * sync to prevent blocking the UI more than necessary.+ */+ if (statusCheck.isOffline) {+ await dbContext.setIsOffline(true);+ onStatus?.(t('common.offlineMode'));+ onOffline?.();+ onSuccess?.(false);+ return true;+ }+// Show appropriate indicator based on what sync will doif (statusCheck.hasNewerVault) {dbContext.setIsSyncing(true);diff --git a/apps/browser-extension/src/utils/WebApiService.ts b/apps/browser-extension/src/utils/WebApiService.tsindex 0e7ce7a6c..22b4dbd06 100644--- a/apps/browser-extension/src/utils/WebApiService.ts+++ b/apps/browser-extension/src/utils/WebApiService.ts@@ -11,6 +11,17 @@ import { storage } from '#imports';type RequestInit = globalThis.RequestInit;+/**+ * Total request timeout for lightweight API calls (status checks, auth, etc.). Kept short so the+ * popup falls back to offline mode quickly when the server is unreachable.+ */+const DEFAULT_REQUEST_TIMEOUT_MS = 5000;++/**+ * Total request timeout for vault download/upload, which can carry a large encrypted blob.+ */+const VAULT_TRANSFER_TIMEOUT_MS = 60000;+/*** Type for the token response from the API.*/@@ -123,6 +134,7 @@ export class WebApiService {const requestOptions: RequestInit = {...options,headers,+ signal: this.buildTimeoutSignal(endpoint, headers, options.signal),};try {@@ -138,6 +150,20 @@ export class WebApiService {}}+ /**+ * Build an AbortSignal that bounds how long a request can run, combined with any caller-supplied+ * signal.+ */+ private buildTimeoutSignal(endpoint: string, headers: Headers, callerSignal?: AbortSignal | null): AbortSignal {+ const path = endpoint.split('?')[0].replace(/^\/+|\/+$/g, '').toLowerCase();+ const isLargeTransfer = path === 'vault' ||+ (headers.get('Accept') ?? '').toLowerCase().includes('application/octet-stream');+ const timeoutSignal = AbortSignal.timeout(+ isLargeTransfer ? VAULT_TRANSFER_TIMEOUT_MS : DEFAULT_REQUEST_TIMEOUT_MS+ );+ return callerSignal ? AbortSignal.any([callerSignal, timeoutSignal]) : timeoutSignal;+ }+/*** Issue GET request to the API.*/diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/webapi/WebApiService.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/webapi/WebApiService.ktindex 38ae5a6d2..f50cca840 100644--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/webapi/WebApiService.kt+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/webapi/WebApiService.kt@@ -39,6 +39,16 @@ class WebApiService(private val context: Context) {private const val CUSTOM_PROXY_HEADERS_KEY = "customProxyHeaders"private const val DEFAULT_API_URL = "https://app.aliasvault.com/api"private const val SHARED_PREFS_NAME = "aliasvault"++ /**+ * Connection-establishment timeout.+ */+ private const val CONNECT_TIMEOUT_MS = 5000++ /**+ * Read timeout. This is an inactivity timeout between successive reads.+ */+ private const val READ_TIMEOUT_MS = 15000}private val sharedPreferences = context.getSharedPreferences(SHARED_PREFS_NAME, Context.MODE_PRIVATE)@@ -256,8 +266,8 @@ class WebApiService(private val context: Context) {val url = URL(urlString)connection = url.openConnection() as HttpURLConnectionconnection.requestMethod = method.uppercase()- connection.connectTimeout = 30000 // 30 seconds- connection.readTimeout = 30000 // 30 seconds+ connection.connectTimeout = CONNECT_TIMEOUT_MS+ connection.readTimeout = READ_TIMEOUT_MSconnection.doInput = true// Add any custom proxy headersdiff --git a/apps/mobile-app/hooks/useVaultSync.ts b/apps/mobile-app/hooks/useVaultSync.tsindex 26aa4d5bd..5c9913f66 100644--- a/apps/mobile-app/hooks/useVaultSync.ts+++ b/apps/mobile-app/hooks/useVaultSync.ts@@ -102,6 +102,17 @@ export const useVaultSync = (): {return false;}+ /*+ * If the lightweight status check already determined the server is unreachable, skip the+ * full sync to avoid additional network calls that can delay the UI.+ */+ if (statusCheck.isOffline) {+ await dbContext.setIsOffline(true);+ console.log('[useVaultSync] Status check reported offline, skipping full sync');+ onOffline?.();+ return true;+ }+// Show appropriate indicator based on what sync will doif (statusCheck.hasNewerVault) {dbContext.setIsSyncing(true);diff --git a/apps/mobile-app/ios/VaultStoreKit/Services/WebApiService.swift b/apps/mobile-app/ios/VaultStoreKit/Services/WebApiService.swiftindex 356c4d393..f8b50d336 100644--- a/apps/mobile-app/ios/VaultStoreKit/Services/WebApiService.swift+++ b/apps/mobile-app/ios/VaultStoreKit/Services/WebApiService.swift@@ -8,6 +8,18 @@ import VaultUtilspublic class WebApiService {private let vaultStore = VaultStore.shared+ /**+ * URLSession configured with explicit timeouts to avoid blocking the main thread for too long+ * when the server is not responding in a suitable time.+ */+ private lazy var urlSession: URLSession = {+ let config = URLSessionConfiguration.default+ config.timeoutIntervalForRequest = 8+ config.timeoutIntervalForResource = 120+ config.waitsForConnectivity = false+ return URLSession(configuration: config)+ }()+// Token storage keysprivate let apiUrlKey = "apiUrl"private let accessTokenKey = "accessToken"@@ -228,7 +240,7 @@ public class WebApiService {}// Execute the request- let (data, urlResponse) = try await URLSession.shared.data(for: request)+ let (data, urlResponse) = try await urlSession.data(for: request)guard let httpResponse = urlResponse as? HTTPURLResponse else {throw NSError(@@ -351,7 +363,6 @@ public class WebApiService {}do {- // Make request with 5 second timeoutlet response = try await executeRequest(method: "GET",endpoint: "Favicon/Extract?url=\(encodedUrl)",