Skip to content

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

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

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 :)

@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
Comment thread internal/reader/fetcher/request_builder.go Outdated
Comment thread internal/reader/fetcher/request_builder.go Outdated
Comment thread internal/reader/fetcher/request_builder.go Outdated
@jvoisin jvoisin marked this pull request as draft June 13, 2026 21:01
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 changes ExecuteRequest and adds a Close method to
RequestBuilder, with the client being (optionally) reused by later calls, so
the underlying TCP/TLS connection (and HTTP/2 stream multiplexing) can be
reused. For example, the finder calls ExecuteRequest 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 :)

Reviewed-by: gudvinr
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.

2 participants