Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for span leaks #1108

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Mixaster995
Copy link
Contributor

Signed-off-by: Mikhail Avramenko avramenkomihail15@gmail.com

Description

Added another span logger for 'infinite' Find case scenario(registry)

Issue link

#1085

How Has This Been Tested?

  • Added unit testing to cover
  • Tested manually
  • Tested by integration testing
  • Have not tested

Types of changes

  • Bug fix
  • New functionallity
  • Documentation
  • Refactoring
  • CI

Signed-off-by: Mikhail Avramenko <avramenkomihail15@gmail.com>
Comment on lines 40 to 43
var loggers []*childSpanLogger
var ticker = time.NewTicker(time.Minute)
var once sync.Once
var lock sync.Mutex
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please let's get rid of static variables to use struct fields.

Suggested change
var loggers []*childSpanLogger
var ticker = time.NewTicker(time.Minute)
var once sync.Once
var lock sync.Mutex

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, done

Comment on lines 46 to 52
type childSpanLogger struct {
span opentracing.Span
childSpan opentracing.Span
entries map[interface{}]interface{}
lock sync.RWMutex
operation string
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please let's try to re-use exist span logger to avoid code duplication.

Suggested change
type childSpanLogger struct {
span opentracing.Span
childSpan opentracing.Span
entries map[interface{}]interface{}
lock sync.RWMutex
operation string
}
type todoSpanLogger struct {
*originalSpanLogger
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, done

Comment on lines 163 to 179
go func() {
for {
select {
case <-ticker.C:
for _, l := range loggers {
if l.span != nil {
l.lock.Lock()
l.childSpan.Finish()
l.childSpan = l.span.Tracer().StartSpan(l.operation, opentracing.ChildOf(l.span.Context()))
l.lock.Unlock()
}
}
case <-ctx.Done():
return
}
}
}()
Copy link
Member

@denis-tingaikin denis-tingaikin Oct 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please let's try to use cond or fanout pattern for subscriptions on events and use shared state.

Suggested change
go func() {
for {
select {
case <-ticker.C:
for _, l := range loggers {
if l.span != nil {
l.lock.Lock()
l.childSpan.Finish()
l.childSpan = l.span.Tracer().StartSpan(l.operation, opentracing.ChildOf(l.span.Context()))
l.lock.Unlock()
}
}
case <-ctx.Done():
return
}
}
}()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, done

Signed-off-by: Mikhail Avramenko <avramenkomihail15@gmail.com>
@edwarnicke
Copy link
Member

@Mixaster995 Is this still a good PR in need of review?

@Mixaster995
Copy link
Contributor Author

@edwarnicke no, it was a test solution for reported problem, but the problem itself is not clear and really hard to reproduce or catch. Thus, we decided to postpone investigation of this problem until better times.

@edwarnicke
Copy link
Member

@Mixaster995 Got it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants