Revert "use a finalizer to close the h2quic.RoundTripper"

This reverts commit 65cea185bd.

The finalizer may run even before the h2quic.RoundTripper
variable falls out of scope. This can result in closing
the session before a HTTP transfer has completed.
This commit is contained in:
Marten Seemann
2017-07-24 18:10:09 +07:00
parent 1060582a18
commit 36ee4bd36b
2 changed files with 0 additions and 19 deletions

View File

@@ -11,8 +11,6 @@ import (
quic "github.com/lucas-clemente/quic-go" quic "github.com/lucas-clemente/quic-go"
"runtime"
"golang.org/x/net/lex/httplex" "golang.org/x/net/lex/httplex"
) )
@@ -93,7 +91,6 @@ func (r *RoundTripper) getClient(hostname string) http.RoundTripper {
defer r.mutex.Unlock() defer r.mutex.Unlock()
if r.clients == nil { if r.clients == nil {
runtime.SetFinalizer(r, finalizer)
r.clients = make(map[string]roundTripCloser) r.clients = make(map[string]roundTripCloser)
} }
@@ -105,10 +102,6 @@ func (r *RoundTripper) getClient(hostname string) http.RoundTripper {
return client return client
} }
func finalizer(r *RoundTripper) {
_ = r.Close()
}
// Close closes the QUIC connections that this RoundTripper has used // Close closes the QUIC connections that this RoundTripper has used
func (r *RoundTripper) Close() error { func (r *RoundTripper) Close() error {
r.mutex.Lock() r.mutex.Lock()

View File

@@ -6,7 +6,6 @@ import (
"errors" "errors"
"io" "io"
"net/http" "net/http"
"runtime"
"time" "time"
quic "github.com/lucas-clemente/quic-go" quic "github.com/lucas-clemente/quic-go"
@@ -197,16 +196,5 @@ var _ = Describe("RoundTripper", func() {
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(len(rt.clients)).To(BeZero()) Expect(len(rt.clients)).To(BeZero())
}) })
It("runs Close when the RoundTripper is garbage collected", func() {
// this is set by getClient, but we can't do that while at the same time injecting the mockClient
runtime.SetFinalizer(rt, finalizer)
rt.clients = make(map[string]roundTripCloser)
cl := &mockClient{}
rt.clients["foo.bar"] = cl
rt = nil // lose the references to the RoundTripper, such that it can be garbage collected
runtime.GC()
Eventually(func() bool { return cl.closed }).Should(BeTrue())
})
}) })
}) })