[http] Aborting a streaming response doesn't close the connection while the server is silent
Describe the bug
Calling AbortController.abort() or reader.cancel() on a plugin fetch response doesn't close the HTTP connection while a body read is waiting for data. The connection closes only when the server sends another byte; if the server stays silent, it never closes until the app exits. The server is therefore not told the client has gone, e.g. for server-sent events or LLM token streams.
First seen on 2.5.8; still present on 2.8.3 (latest).
Reproduction
- A Tauri 2.12.3 app with only
tauri-plugin-http2.8.3 and@tauri-apps/plugin-http2.8.3. Capability:{ "identifier": "http:default", "allow": [{ "url": "http://127.0.0.1:*/*" }] } - A local server that writes one chunk, then stays silent, and logs when the client closes the socket:
import http from 'node:http'; http.createServer((req, res) => { res.writeHead(200, { 'content-type': 'text/event-stream', 'access-control-allow-origin': '*' }); res.write('data: chunk1\n\n'); res.on('close', () => console.log(Date.now(), 'client closed')); }).listen(47587, '127.0.0.1'); - In the page, with the plugin's
fetch:import { fetch } from '@tauri-apps/plugin-http'; const ac = new AbortController(); const reader = (await fetch('http://127.0.0.1:47587/', { signal: ac.signal })).body.getReader(); await reader.read(); // first chunk reader.read(); // pending read, as a streaming client has console.log(Date.now(), 'abort'); ac.abort(); // same result with reader.cancel()
Expected behavior
The server logs client closed immediately after abort, as it does when the same page uses the webview's own fetch.
Actual behavior
Time from abort() (or reader.cancel()) to the server seeing the connection close:
| Server after the first chunk | Webview's own fetch |
Plugin fetch |
|---|---|---|
| Stays silent | 3–14 ms | Never (closes when the app exits) |
| Sends a chunk every 600 ms | ~4 ms | ~450 ms: only when the next chunk arrives |
Node 24 fetch and curl against the same server close within 4 ms, so the server detects closes correctly.
Full tauri info output
OS: Ubuntu 24.04 aarch64
webkit2gtk-4.1: 2.52.3
rustc: 1.98.1
node: 24.20.0
tauri: 2.12.3
tauri-plugin-http: 2.8.3
@tauri-apps/plugin-http: 2.8.3
Tested on Linux only, under xvfb-run. The webview fetch control in the same environment closes immediately.
Additional context
Related: #2557 / #2562 (aborting a streaming response), #3227 (dropBody on stream cancellation).