From 8ab88976cfcba07b1c57e841492c48fa5a671fe2 Mon Sep 17 00:00:00 2001 From: Frank Schroeder Date: Thu, 29 Jun 2017 13:09:51 +0200 Subject: [PATCH] serf: monkey patch data race in github.com/hashicorp/serf https://github.com/hashicorp/serf/pull/476 This should be replaced when the patch is merged upstream and the library is upgraded. --- vendor/github.com/hashicorp/serf/serf/delegate.go | 3 ++- vendor/github.com/hashicorp/serf/serf/serf.go | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/vendor/github.com/hashicorp/serf/serf/delegate.go b/vendor/github.com/hashicorp/serf/serf/delegate.go index 8f51cb7d08..1535315027 100644 --- a/vendor/github.com/hashicorp/serf/serf/delegate.go +++ b/vendor/github.com/hashicorp/serf/serf/delegate.go @@ -251,7 +251,8 @@ func (d *delegate) MergeRemoteState(buf []byte, isJoin bool) { // If we are doing a join, and eventJoinIgnore is set // then we set the eventMinTime to the EventLTime. This // prevents any of the incoming events from being processed - if isJoin && d.serf.eventJoinIgnore { + eventJoinIgnore := d.serf.eventJoinIgnore.Load().(bool) + if isJoin && eventJoinIgnore { d.serf.eventLock.Lock() if pp.EventLTime > d.serf.eventMinTime { d.serf.eventMinTime = pp.EventLTime diff --git a/vendor/github.com/hashicorp/serf/serf/serf.go b/vendor/github.com/hashicorp/serf/serf/serf.go index 3a88d9b0d9..af48e53a2d 100644 --- a/vendor/github.com/hashicorp/serf/serf/serf.go +++ b/vendor/github.com/hashicorp/serf/serf/serf.go @@ -13,6 +13,7 @@ import ( "os" "strconv" "sync" + "sync/atomic" "time" "github.com/armon/go-metrics" @@ -74,7 +75,7 @@ type Serf struct { eventBroadcasts *memberlist.TransmitLimitedQueue eventBuffer []*userEvents - eventJoinIgnore bool + eventJoinIgnore atomic.Value eventMinTime LamportTime eventLock sync.RWMutex @@ -258,6 +259,7 @@ func Create(conf *Config) (*Serf, error) { shutdownCh: make(chan struct{}), state: SerfAlive, } + serf.eventJoinIgnore.Store(false) // Check that the meta data length is okay if len(serf.encodeTags(conf.Tags)) > memberlist.MetaMaxSize { @@ -593,9 +595,9 @@ func (s *Serf) Join(existing []string, ignoreOld bool) (int, error) { // Ignore any events from a potential join. This is safe since we hold // the joinLock and nobody else can be doing a Join if ignoreOld { - s.eventJoinIgnore = true + s.eventJoinIgnore.Store(true) defer func() { - s.eventJoinIgnore = false + s.eventJoinIgnore.Store(false) }() }