Skip to content

Commit f0f479a

Browse files
authored
Merge pull request #113 from nvanbenschoten/avoidDeadlock
Avoid deadlocking when Collector Closed concurrently with Collect call
2 parents e6e8db0 + 729be03 commit f0f479a

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

collector-http.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ func NewHTTPCollector(url string, options ...HTTPOption) (Collector, error) {
116116
func (c *HTTPCollector) Collect(s *zipkincore.Span) error {
117117
select {
118118
case c.spanc <- s:
119+
// Accepted.
120+
case <-c.quit:
121+
// Collector concurrently closed.
119122
default:
120123
c.logger.Log("msg", "queue full, disposing spans.", "size", len(c.spanc))
121124
}

collector-scribe.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,13 @@ func NewScribeCollector(addr string, timeout time.Duration, options ...ScribeOpt
113113

114114
// Collect implements Collector.
115115
func (c *ScribeCollector) Collect(s *zipkincore.Span) error {
116-
c.spanc <- s
117-
return nil // accepted
116+
select {
117+
case c.spanc <- s:
118+
// Accepted.
119+
case <-c.quit:
120+
// Collector concurrently closed.
121+
}
122+
return nil
118123
}
119124

120125
// Close implements Collector.

0 commit comments

Comments
 (0)