Skip to content

perf(reader): reuse TCP connection across well-known feed URL probes#4342

Open
jvoisin wants to merge 1 commit into
miniflux:mainfrom
jvoisin:reuse
Open

perf(reader): reuse TCP connection across well-known feed URL probes#4342
jvoisin wants to merge 1 commit into
miniflux:mainfrom
jvoisin:reuse

Conversation

@jvoisin

@jvoisin jvoisin commented May 17, 2026

Copy link
Copy Markdown
Collaborator

findSubscriptionsFromWellKnownURLs sequentially probes a list of well-known feed paths against a single host. Each probe went through ExecuteRequest, which builds a fresh *http.Client, sends "Connection: close", and tears the TCP/TLS connection down, meaning the N probes paid N TLS handshakes against the same host.

This commit adds a ExecuteRequestKeepalive and a Close method to RequestBuilder. The keep-alive client is lazily built on first use and stashed on the builder; later calls reuse it, so the underlying TCP/TLS connection (and HTTP/2 stream multiplexing) can be reused. The finder calls ExecuteRequestKeepalive in the probe loop and defers Close to release the pool.

There is also a drive-by fix of an issue in the request path: per-request header tweaks (Accept-Encoding, Accept, Connection) were written directly into the builder's shared headers map, leaking state back into the builder and racing for any concurrent caller. The header map is now cloned before mutating it.

Of course, tests were added :)

findSubscriptionsFromWellKnownURLs sequentially probes a list of
well-known feed paths against a single host. Each probe went through
ExecuteRequest, which builds a fresh *http.Client, sends "Connection:
close", and tears the TCP/TLS connection down, meaning the N probes paid N TLS
handshakes against the same host.

This commit adds a ExecuteRequestKeepalive and a Close method to
RequestBuilder. The keep-alive client is lazily built on first use and stashed
on the builder; later calls reuse it, so the underlying TCP/TLS connection (and
HTTP/2 stream multiplexing) can be reused. The finder calls
ExecuteRequestKeepalive in the probe loop and defers Close to release the pool.

There is also a drive-by fix of an issue in the request path: per-request header tweaks
(Accept-Encoding, Accept, Connection) were written directly into the
builder's shared headers map, leaking state back into the builder and
racing for any concurrent caller. The header map is now cloned before
mutating it.

Of course, tests were added :)
@jvoisin

jvoisin commented May 17, 2026

Copy link
Copy Markdown
Collaborator Author

I'm not that happy about the implementation, but I think it's the least worst one.

dsh2dsh added a commit to dsh2dsh/miniflux that referenced this pull request May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant