Skip to content
This repository has been archived by the owner on Feb 15, 2023. It is now read-only.

Commit

Permalink
go reactive: Cancel context after each reactive Run
Browse files Browse the repository at this point in the history
Summary: Some pieces of code will hold onto the context waiting for it
to be done (usually in a goroutine).  This means that all the objects
that are stored on the context are held until the original context is
marked as "done".  This would not happen until the websocket/http
request finishes.  So for continous requests we have a leak where each
intermediary context is holding onto the entire cache stack (and
anything else on the context) until we reset the websocket connection.

This commit adds a cancel to context for each reactive.Run.  This should
allow all code that depends on the context.Done() to be able to clear
between runs.
  • Loading branch information
Will Hughes authored and willhug committed Aug 12, 2019
1 parent 3da7303 commit ab0b461
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion reactive/rerunner.go
Expand Up @@ -369,7 +369,13 @@ func (r *Rerunner) run() {
time.Sleep(WriteThenReadDelay)
}
r.cache.cleanInvalidated()
ctx := context.WithValue(r.ctx, cacheKey{}, r.cache)

// Cancel the context passed to "run". Canceling the context ensures that
// libraries let go of the context when they might otherwise hold onto it long
// past this run.
ctx, cancel := context.WithCancel(r.ctx)
defer cancel()
ctx = context.WithValue(ctx, cacheKey{}, r.cache)
ctx = context.WithValue(ctx, dependencySetKey{}, &dependencySet{})

currentComputation, err := run(ctx, r.f)
Expand Down

0 comments on commit ab0b461

Please sign in to comment.