Skip to content

Commit

Permalink
fix dataraces by aws#102
Browse files Browse the repository at this point in the history
  • Loading branch information
t-yuki authored and Logan Hanks committed Jul 2, 2019
1 parent 52ef590 commit 445cf09
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions xray/httptrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ func (xt *HTTPSubsegments) GetConn(hostPort string) {
// DNSStart begins a dns subsegment if the HTTP operation
// subsegment is still in progress.
func (xt *HTTPSubsegments) DNSStart(info httptrace.DNSStartInfo) {
xt.mu.Lock()
defer xt.mu.Unlock()
if GetSegment(xt.opCtx).safeInProgress() && xt.connCtx != nil {
xt.dnsCtx, _ = BeginSubsegment(xt.connCtx, "dns")
}
Expand All @@ -71,6 +73,8 @@ func (xt *HTTPSubsegments) DNSDone(info httptrace.DNSDoneInfo) {
// ConnectStart begins a dial subsegment if the HTTP operation
// subsegment is still in progress.
func (xt *HTTPSubsegments) ConnectStart(network, addr string) {
xt.mu.Lock()
defer xt.mu.Unlock()
if GetSegment(xt.opCtx).safeInProgress() && xt.connCtx != nil {
xt.connectCtx, _ = BeginSubsegment(xt.connCtx, "dial")
}
Expand Down
4 changes: 4 additions & 0 deletions xray/segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ func (seg *Segment) RemoveSubsegment(remove *Segment) bool {
seg.rawSubsegments[len(seg.rawSubsegments)-1] = nil
seg.rawSubsegments = seg.rawSubsegments[:len(seg.rawSubsegments)-1]

if seg.ParentSegment != seg {
seg.ParentSegment.Lock()
defer seg.ParentSegment.Unlock()
}
seg.ParentSegment.totalSubSegments--
seg.openSegments--
return true
Expand Down

0 comments on commit 445cf09

Please sign in to comment.