From 44271a8ec82912af4e3d9d2bdaab5eb577e7f21c Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Mon, 19 Dec 2016 12:00:42 +0700 Subject: [PATCH] fix mutexes for writing requests in h2quic client --- h2quic/client.go | 4 ++-- h2quic/request_writer.go | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/h2quic/client.go b/h2quic/client.go index d34863eb..58534711 100644 --- a/h2quic/client.go +++ b/h2quic/client.go @@ -158,9 +158,10 @@ func (c *Client) Do(req *http.Request) (*http.Response, error) { for c.encryptionLevel != protocol.EncryptionForwardSecure { c.cryptoChangedCond.Wait() } - hdrChan := make(chan *http.Response) c.responses[dataStreamID] = hdrChan + c.mutex.Unlock() + dataStream, err := c.client.OpenStream(dataStreamID) if err != nil { return nil, err @@ -169,7 +170,6 @@ func (c *Client) Do(req *http.Request) (*http.Response, error) { if err != nil { return nil, err } - c.mutex.Unlock() var res *http.Response select { diff --git a/h2quic/request_writer.go b/h2quic/request_writer.go index c77fcbd6..7f421adc 100644 --- a/h2quic/request_writer.go +++ b/h2quic/request_writer.go @@ -6,6 +6,7 @@ import ( "net/http" "strconv" "strings" + "sync" "golang.org/x/net/http2" "golang.org/x/net/http2/hpack" @@ -16,6 +17,7 @@ import ( ) type requestWriter struct { + mutex sync.Mutex headerStream utils.Stream henc *hpack.Encoder @@ -36,6 +38,10 @@ func (w *requestWriter) WriteRequest(req *http.Request, dataStreamID protocol.St // TODO: add support for trailers // TODO: add support for gzip compression // TODO: write continuation frames, if the header frame is too long + + w.mutex.Lock() + defer w.mutex.Unlock() + w.encodeHeaders(req, false, "", actualContentLength(req)) h2framer := http2.NewFramer(w.headerStream, nil) return h2framer.WriteHeaders(http2.HeadersFrameParam{