Skip to content

Modern Docker Management, Designed for Everyone

fix: activity status only showing on first browser tab (#2951)

Kyle Mendell568832269f6a
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index ea7f0d8a0..97679f402 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -283,9 +283,9 @@ jobs:
- name: Pull and save test images
run: |
- docker pull ghcr.io/linuxserver/nginx:latest
+ docker pull public.ecr.aws/nginx/nginx:stable-alpine
docker pull ghcr.io/linuxserver/radarr:nightly
- docker save ghcr.io/linuxserver/nginx:latest ghcr.io/linuxserver/radarr:nightly > /tmp/test-images.tar
+ docker save public.ecr.aws/nginx/nginx:stable-alpine ghcr.io/linuxserver/radarr:nightly > /tmp/test-images.tar
- name: Setup and Install Playwright Dependencies
run: just deps install tests
diff --git a/backend/pkg/utils/httpx/request.go b/backend/pkg/utils/httpx/request.go
index eb01c4407..0404a589c 100644
--- a/backend/pkg/utils/httpx/request.go
+++ b/backend/pkg/utils/httpx/request.go
@@ -14,7 +14,10 @@ type HeaderSetter interface {
func SetJSONStreamHeaders(headers HeaderSetter) {
headers.SetHeader("Content-Type", "application/x-json-stream")
- headers.SetHeader("Cache-Control", "no-cache")
+ // no-store keeps proxies from caching or collapsing identical concurrent
+ // stream requests (e.g. two browser tabs), which would otherwise leave only
+ // the first connection attached to the live upstream stream.
+ headers.SetHeader("Cache-Control", "no-store, no-cache, must-revalidate")
headers.SetHeader("Connection", "keep-alive")
headers.SetHeader("X-Accel-Buffering", "no")
}
diff --git a/frontend/src/lib/services/activity-service.ts b/frontend/src/lib/services/activity-service.ts
index 5b2426b28..96db98e7d 100644
--- a/frontend/src/lib/services/activity-service.ts
+++ b/frontend/src/lib/services/activity-service.ts
@@ -3,6 +3,7 @@ import { environmentStore } from '$lib/stores/environment.store.svelte';
import type { Activity, ActivityClearHistoryResult, ActivityDetail } from '$lib/types/activity.type';
import type { Paginated, SearchPaginationSortRequest } from '$lib/types/shared';
import { transformPaginationParams } from '$lib/utils/tables';
+import { streamCacheBuster } from '$lib/utils/streaming';
class ActivityService extends BaseAPIService {
private async resolveEnvironmentId(environmentId?: string): Promise<string> {
@@ -33,7 +34,7 @@ class ActivityService extends BaseAPIService {
getActivityStreamUrl(limit = 50): string {
const baseUrl = this.api.defaults.baseURL.replace(/\/+$/, '');
- const params = new URLSearchParams({ limit: String(limit) });
+ const params = new URLSearchParams({ limit: String(limit), _: streamCacheBuster() });
return `${baseUrl}/activities/stream?${params.toString()}`;
}
diff --git a/frontend/src/lib/services/dashboard-service.ts b/frontend/src/lib/services/dashboard-service.ts
index 5ea90d742..b2dd2622d 100644
--- a/frontend/src/lib/services/dashboard-service.ts
+++ b/frontend/src/lib/services/dashboard-service.ts
@@ -1,4 +1,5 @@
import BaseAPIService, { handleUnauthorizedResponseInternal } from './api-service';
+import { streamCacheBuster } from '$lib/utils/streaming';
import type { DashboardSnapshot } from '$lib/types/shared';
interface GetDashboardOptions {
@@ -17,6 +18,7 @@ class DashboardService extends BaseAPIService {
if (debugAllGood) {
params.set('debugAllGood', 'true');
}
+ params.set('_', streamCacheBuster());
const query = params.toString();
return `${baseUrl}/dashboard/stream${query ? `?${query}` : ''}`;
}
diff --git a/frontend/src/lib/utils/streaming.ts b/frontend/src/lib/utils/streaming.ts
index a3d9f1af0..5a50167b6 100644
--- a/frontend/src/lib/utils/streaming.ts
+++ b/frontend/src/lib/utils/streaming.ts
@@ -1,3 +1,20 @@
+/**
+ * Returns a value unique to each call, for use as a cache-busting query param on
+ * stream URLs. Without it, intermediaries that key on the URL — a reverse proxy
+ * collapsing identical in-flight GETs, the service worker cache, the browser HTTP
+ * cache — can collapse multiple tabs' identical stream requests onto a single
+ * upstream connection, so only the first tab receives live events.
+ *
+ * `crypto.randomUUID()` is only defined in secure contexts (HTTPS / localhost),
+ * so fall back to a timestamp + random suffix for plain-HTTP deployments.
+ */
+export function streamCacheBuster(): string {
+ if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
+ return crypto.randomUUID();
+ }
+ return `${Date.now()}-${Math.random().toString(36).slice(2)}`;
+}
+
export async function readNdjsonStream(
body: ReadableStream<Uint8Array>,
onMessage?: (data: any) => void,
diff --git a/frontend/src/service-worker.ts b/frontend/src/service-worker.ts
index ac6be7783..d6ce23367 100644
--- a/frontend/src/service-worker.ts
+++ b/frontend/src/service-worker.ts
@@ -7,7 +7,6 @@ import { build, files, version } from '$service-worker';
const self = globalThis.self as unknown as ServiceWorkerGlobalScope;
-const DATA_CACHE = `data-cache-${version}`;
const CACHE = `cache-${version}`;
const ASSETS = [...build, ...files];
@@ -22,6 +21,10 @@ self.addEventListener('install', (event) => {
}
event.waitUntil(addFilesToCache());
+
+ // Activate this worker immediately rather than waiting for all tabs to close,
+ // so the API-bypass fix takes effect on the next navigation.
+ self.skipWaiting();
});
self.addEventListener('activate', (event) => {
@@ -31,7 +34,7 @@ self.addEventListener('activate', (event) => {
const keyList = await caches.keys();
await Promise.all(
keyList.map((key) => {
- if (key !== CACHE && key !== DATA_CACHE) {
+ if (key !== CACHE) {
console.log('[ServiceWorker] Removing old cache', key);
return caches.delete(key);
}
@@ -39,46 +42,35 @@ self.addEventListener('activate', (event) => {
);
}
- event.waitUntil(deleteOldCaches());
- return self.clients.claim();
+ // Make both the cache cleanup and taking control of already-open tabs part of
+ // the activation lifetime. Returning clients.claim() from the listener isn't
+ // enough — the service worker event system ignores the return value, so the
+ // claim could lose the race to activation completing and leave existing tabs
+ // controlled by the old worker (which still caches /api/ streams) until a full
+ // reload, leaving the multi-tab bug unfixed for the very tabs this repairs.
+ event.waitUntil(Promise.all([deleteOldCaches(), self.clients.claim()]));
});
self.addEventListener('fetch', (event) => {
- console.log('[ServiceWorker] Fetch', event.request.url);
-
if (event.request.method !== 'GET') return;
const url = new URL(event.request.url);
- const isApiRequest = url.pathname.startsWith('/api/');
-
- async function respond() {
- if (isApiRequest) {
- const cache = await caches.open(DATA_CACHE);
- try {
- const response = await fetch(event.request);
-
- if (response.status === 200) {
- cache.put(event.request, response.clone());
- }
- return response;
- } catch (err) {
- const cachedResponse = await cache.match(event.request);
- if (cachedResponse) {
- return cachedResponse;
- }
- throw err;
- }
- } else {
- const cache = await caches.open(CACHE);
- const cachedResponse = await cache.match(event.request);
+ // Never intercept API requests. Caching the never-ending `/api/.../stream`
+ // responses leaked memory and collapsed every tab onto a single cached
+ // connection, so only the first tab received live events. Let API requests
+ // — including streams — go straight to the network, one per tab.
+ if (url.pathname.startsWith('/api/')) return;
- if (cachedResponse) {
- return cachedResponse;
- }
+ async function respond() {
+ const cache = await caches.open(CACHE);
+ const cachedResponse = await cache.match(event.request);
- return fetch(event.request);
+ if (cachedResponse) {
+ return cachedResponse;
}
+
+ return fetch(event.request);
}
event.respondWith(respond());
diff --git a/tests/setup/project.data.ts b/tests/setup/project.data.ts
index c5ec82aa7..97c916402 100644
--- a/tests/setup/project.data.ts
+++ b/tests/setup/project.data.ts
@@ -7,7 +7,7 @@ export const TEST_COMPOSE_YAML = `configs:
services:
nginx:
- image: ghcr.io/linuxserver/nginx:latest
+ image: public.ecr.aws/nginx/nginx:stable-alpine
container_name: \${CONTAINER_NAME}
configs:
- source: some_content
diff --git a/tests/spec/project.spec.ts b/tests/spec/project.spec.ts
index 819c4aadd..0db5265ec 100644
--- a/tests/spec/project.spec.ts
+++ b/tests/spec/project.spec.ts
@@ -709,7 +709,11 @@ test.describe('New Compose Project Page', () => {
const deployResponse = await deployResponsePromise;
expect(deployResponse.ok()).toBe(true);
- expect(await deployResponse.finished()).toBeNull();
+ // Don't await deployResponse.finished() here: for a chunked NDJSON stream
+ // consumed via fetch().body, Playwright's network-layer finished() doesn't
+ // reliably resolve even after the server closes the response and the UI
+ // updates to "running" — it hangs until the test timeout. Deploy completion
+ // is verified below via the running-status poll and the activity-success check.
const projectId = createdProjectId ?? getProjectIdFromPageUrl(page.url());
await expect