You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Simplify or fix the http.DefaultTransport clone fallback in registry NewTransport #32682
Split out of #31386, where @ogulcanaydogan noted this as "the Go 1.20-era cloner fallback in pkg/registry/transport.go". It is unrelated to the oras-go workarounds that issue tracked, so filing it separately.
NewTransport in pkg/registry/transport.go:
func NewTransport(debug bool) *retry.Transport {
// clone http.DefaultTransport so mutations (e.g. TLS config) are not
// reflected globally
transport := http.DefaultTransport
if t, ok := transport.(*http.Transport); ok {
transport = t.Clone()
}
...
}
The type assertion dates from when (*http.Transport).Clone was newer and the guard was worth having. The standard library documents http.DefaultTransport as a *http.Transport, so in practice the assertion always succeeds and the fallback branch never runs — we now require Go 1.26 (#32078), so there is no supported toolchain where this differs.
Worth being precise about what the fallback actually guards, though: http.DefaultTransport is a package-level variable of interface type, so a caller (or an imported package) can reassign it to some other RoundTripper. If that happened, today's code silently falls through and we would wrap and hand out the shared global without cloning it — which is exactly the aliasing the comment says we are trying to avoid. So the branch is not strictly dead; it is a silent-and-wrong path rather than an impossible one.
Two reasonable directions:
Drop the assertion and clone http.DefaultTransport.(*http.Transport) directly, accepting a panic if someone has replaced it. Simplest, and fails loudly instead of silently sharing state.
Keep a guard but make the fallback meaningful — construct a fresh &http.Transport{} (or log) rather than aliasing the global.
Either is a small change; mostly this needs a decision on which behavior we want. Flagging it because the current shape reads as dead code but is not quite.
Activity