Skip to content

Commit

Permalink
fix nilp error by aws#102 for tls conn
Browse files Browse the repository at this point in the history
  • Loading branch information
t-yuki committed May 9, 2019
1 parent 2d95a62 commit 65a6212
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
43 changes: 43 additions & 0 deletions xray/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,49 @@ func TestRoundTripReuseDatarace(t *testing.T) {
wg.Wait()
}

func TestRoundTripReuseTLSDatarace(t *testing.T) {
ts := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
b := []byte(`200 - Nothing to see`)
w.WriteHeader(http.StatusOK)
w.Write(b)
}))
defer ts.Close()

certpool := x509.NewCertPool()
certpool.AddCert(ts.Certificate())
tr := &http.Transport{
TLSClientConfig: &tls.Config{
RootCAs: certpool,
},
}
rt := &roundtripper{
Base: tr,
}

wg := sync.WaitGroup{}
n := 30
wg.Add(n)
for i := 0; i < n; i++ {
go func() {
defer wg.Done()
reader := strings.NewReader("")
ctx, root := BeginSegment(context.Background(), "Test")
req, _ := http.NewRequest("GET", ts.URL, reader)
req = req.WithContext(ctx)
res, err := rt.RoundTrip(req)
assert.NoError(t, err)
ioutil.ReadAll(res.Body)
res.Body.Close() // make net/http/transport.go connection reuse
root.Close(nil)
}()
}
for i := 0; i < n; i++ {
_, e := TestDaemon.Recv()
assert.NoError(t, e)
}
wg.Wait()
}

func TestRoundTripHttp2Datarace(t *testing.T) {
ts := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
b := []byte(`200 - Nothing to see`)
Expand Down
2 changes: 1 addition & 1 deletion xray/httptrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (xt *HTTPSubsegments) ConnectDone(network, addr string, err error) {
// TLSHandshakeStart begins a tls subsegment if the HTTP operation
// subsegment is still in progress.
func (xt *HTTPSubsegments) TLSHandshakeStart() {
if GetSegment(xt.opCtx).safeInProgress() {
if GetSegment(xt.opCtx).safeInProgress() && xt.connCtx != nil {
xt.tlsCtx, _ = BeginSubsegment(xt.connCtx, "tls")
}
}
Expand Down

0 comments on commit 65a6212

Please sign in to comment.