From 812ca4e3d7e4345dfc71a422e1ea3a3ff130dd3b Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Tue, 27 Oct 2026 16:36:14 +0100 Subject: [PATCH] fix(web-svc-coturn): size the TURN allocation quota for Talk calls and test a six-person call coturn ran with a fixed --total-quota=100 for the whole server. A Nextcloud Talk call through the HPB opens N peer connections per participant and one allocation per TURN transport, about 2*N^2 allocations, so calls of more than about five participants ran out. services.coturn.total_quota now sets the quota, 2000 by default; on echoserver eight participants held connected media with it. The Nextcloud Playwright suite gains test-talk-call-capacity, gated like the Talk admin test: as administrator it creates a public room through the Talk API, joins six guests in separate contexts with fake media, and requires every guest to hold a connected peer connection to every participant and no TURN 486 Allocation Quota Reached. Co-Authored-By: Claude Opus 5.5 (1M context) --- .../files/playwright/playwright.spec.js | 1 + .../playwright/test-talk-call-capacity.js | 109 ++++++++++++++++++ roles/web-svc-coturn/README.md | 1 + roles/web-svc-coturn/meta/services.yml | 1 + roles/web-svc-coturn/templates/compose.yml.j2 | 2 +- roles/web-svc-coturn/vars/main.yml | 1 + 6 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 roles/web-app-nextcloud/files/playwright/test-talk-call-capacity.js diff --git a/roles/web-app-nextcloud/files/playwright/playwright.spec.js b/roles/web-app-nextcloud/files/playwright/playwright.spec.js index 7b62b8a83e..ff114cd6d8 100644 --- a/roles/web-app-nextcloud/files/playwright/playwright.spec.js +++ b/roles/web-app-nextcloud/files/playwright/playwright.spec.js @@ -19,6 +19,7 @@ test.use({ test.beforeEach(shared.beforeEach); require("./test-talk-admin-settings").register(shared); +require("./test-talk-call-capacity").register(shared); require("./test-login-admin-oidc").register(shared); require("./test-login-admin-native").register(shared); require("./test-login-biber-oidc").register(shared); diff --git a/roles/web-app-nextcloud/files/playwright/test-talk-call-capacity.js b/roles/web-app-nextcloud/files/playwright/test-talk-call-capacity.js new file mode 100644 index 0000000000..5eacba51c1 --- /dev/null +++ b/roles/web-app-nextcloud/files/playwright/test-talk-call-capacity.js @@ -0,0 +1,109 @@ +const { test, expect } = require("@playwright/test"); +const { resolveTimeout, isOnionTarget } = require("./timeouts"); +const { decodeDotenvQuotedValue, gotoOnion } = require("./personas"); + +const talkEnabled = decodeDotenvQuotedValue(process.env.NEXTCLOUD_TALK_SETTINGS_CHECK_ENABLED) === "true"; +const callParticipants = 6; +const ocsHeaders = { "OCS-APIRequest": "true", Accept: "application/json" }; +const joinCallPattern = /^(join call|start call|anruf beitreten|anruf starten)$/i; +const leaveCallPattern = /^(leave call|anruf verlassen)$/i; +const displayNamePattern = /display name|anzeigename/i; +const turnQuotaReachedCode = 486; + +function trackPeerConnections() { + const Original = window.RTCPeerConnection; + const stats = { connections: [], iceErrorCodes: [] }; + window.__talkCallStats = stats; + function Tracked(...args) { + const connection = new Original(...args); + stats.connections.push(connection); + connection.addEventListener("icecandidateerror", (event) => stats.iceErrorCodes.push(event.errorCode)); + return connection; + } + Tracked.prototype = Original.prototype; + Object.setPrototypeOf(Tracked, Original); + window.RTCPeerConnection = Tracked; +} + +function readCallStats(page) { + return page.evaluate(() => { + const stats = window.__talkCallStats; + return { + connected: stats.connections.filter((connection) => connection.connectionState === "connected").length, + iceErrorCodes: stats.iceErrorCodes, + }; + }); +} + +async function createPublicRoom(page, baseUrl) { + const response = await page.request.post(`${baseUrl}/ocs/v2.php/apps/spreed/api/v4/room`, { + headers: ocsHeaders, + data: { roomType: 3, roomName: `Playwright call capacity ${Date.now()}` }, + }); + expect(response.ok(), `creating the public Talk room answered HTTP ${response.status()}`).toBeTruthy(); + return (await response.json()).ocs.data.token; +} + +async function joinCallAsGuest(browser, roomUrl, name) { + const context = await browser.newContext({ ignoreHTTPSErrors: true, permissions: ["camera", "microphone"] }); + await context.addInitScript(trackPeerConnections); + const page = await context.newPage(); + await gotoOnion(page, roomUrl, { waitUntil: "domcontentloaded", timeout: resolveTimeout(60_000) }); + const dialog = page.getByRole("dialog"); + await dialog.getByLabel(displayNamePattern).first().fill(name, { timeout: resolveTimeout(60_000) }); + const joinButton = dialog.getByRole("button", { name: joinCallPattern }).last(); + await expect(joinButton, `${name}: the join button stays disabled after the display name`).toBeEnabled({ + timeout: resolveTimeout(30_000), + }); + await joinButton.click({ timeout: resolveTimeout(30_000) }); + await expect(page.getByRole("button", { name: leaveCallPattern }).first(), `${name} never entered the call`).toBeVisible({ + timeout: resolveTimeout(60_000), + }); + return { name, page, context }; +} + +exports.register = function (shared) { + test("nextcloud talk call holds more than five participants", async ({ browser }) => { + test.skip(!talkEnabled, "Talk is disabled in the current Playwright env"); + test.skip(isOnionTarget(), "Nextcloud Talk realtime (HPB signaling + STUN/TURN) is WebRTC; not reachable over Tor"); + test.setTimeout(resolveTimeout(15 * 60_000)); + + const baseUrl = shared.env.nextcloudBaseUrl; + const adminContext = await browser.newContext({ ignoreHTTPSErrors: true }); + const adminPage = await adminContext.newPage(); + const guests = []; + let token = ""; + + try { + await shared.loginToStandaloneNextcloud(adminPage); + token = await createPublicRoom(adminPage, baseUrl); + + for (let index = 1; index <= callParticipants; index += 1) { + guests.push(await joinCallAsGuest(browser, `${baseUrl}/call/${token}`, `Playwright guest ${index}`)); + } + + for (const guest of guests) { + await expect + .poll(async () => (await readCallStats(guest.page)).connected, { + timeout: resolveTimeout(120_000), + message: `${guest.name} must hold a connected peer connection to every participant of the ${callParticipants}-person call`, + }) + .toBeGreaterThanOrEqual(callParticipants); + expect( + (await readCallStats(guest.page)).iceErrorCodes, + `${guest.name}: TURN answered ${turnQuotaReachedCode} Allocation Quota Reached`, + ).not.toContain(turnQuotaReachedCode); + } + } finally { + for (const guest of guests) { + await guest.context.close().catch(() => {}); + } + if (token) { + await adminPage.request + .delete(`${baseUrl}/ocs/v2.php/apps/spreed/api/v4/room/${token}`, { headers: ocsHeaders }) + .catch(() => {}); + } + await adminContext.close().catch(() => {}); + } + }); +}; diff --git a/roles/web-svc-coturn/README.md b/roles/web-svc-coturn/README.md index bf4a9773a2..73134bbb5d 100644 --- a/roles/web-svc-coturn/README.md +++ b/roles/web-svc-coturn/README.md @@ -77,6 +77,7 @@ Solid `1:1` edges are fixed relationships; dashed `0..1` edges are conditional ( - Automatic TLS handling via `sys-stk-front-base` - TURN and STUN support over TCP and UDP - Configurable relay port ranges for scaling +- Configurable server-wide allocation quota (`services.coturn.total_quota`, default 2000); size it at about 2·N² for every concurrent Nextcloud Talk call with N participants, as each participant opens N peer connections and requests one allocation per TURN transport - Integration into Infinito.Nexus inventory/variable system ## Quick Setup diff --git a/roles/web-svc-coturn/meta/services.yml b/roles/web-svc-coturn/meta/services.yml index 768dcf9ccb..ed17e5a592 100644 --- a/roles/web-svc-coturn/meta/services.yml +++ b/roles/web-svc-coturn/meta/services.yml @@ -12,6 +12,7 @@ coturn: version: 4.18.0 min_storage: 246MB user_auth_enabled: false + total_quota: 2000 cpus: 1.0 mem_reservation: 512m mem_limit: 1g diff --git a/roles/web-svc-coturn/templates/compose.yml.j2 b/roles/web-svc-coturn/templates/compose.yml.j2 index e9b4b8dc58..53a6e26cdf 100644 --- a/roles/web-svc-coturn/templates/compose.yml.j2 +++ b/roles/web-svc-coturn/templates/compose.yml.j2 @@ -53,7 +53,7 @@ {% endif %} --realm="${COTURN_REALM}" --fingerprint - --total-quota=100 + --total-quota={{ COTURN_TOTAL_QUOTA }} --stale-nonce --no-multicast-peers --no-cli diff --git a/roles/web-svc-coturn/vars/main.yml b/roles/web-svc-coturn/vars/main.yml index 1fd172c9aa..a198b9a548 100644 --- a/roles/web-svc-coturn/vars/main.yml +++ b/roles/web-svc-coturn/vars/main.yml @@ -11,6 +11,7 @@ COTURN_STUN_TURN_PORT: "{{ lookup('config', application_id, 'services.coturn.por COTURN_STUN_TURN_PORT_TLS: "{{ lookup('config', application_id, 'services.coturn.ports.public.stun_turn_tls') }}" COTURN_RELAY_PORT_START: "{{ lookup('config', application_id, 'services.coturn.ports.public.relay.start') }}" COTURN_RELAY_PORT_END: "{{ lookup('config', application_id, 'services.coturn.ports.public.relay.end') }}" +COTURN_TOTAL_QUOTA: "{{ lookup('config', application_id, 'services.' ~ entity_name ~ '.total_quota') }}" COTURN_USER_NAME: "{{ lookup('users', 'coturnconsumer').username }}" COTURN_USER_PASSWORD: "{{ lookup('users', 'coturnconsumer').password }}"