From 05bb44632302d38026c9bd9c0dabfc3015ee5f57 Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Fri, 27 Oct 2017 13:27:24 -0700 Subject: [PATCH 1/3] Node access is done using locked Node copy Fixes https://github.com/hashicorp/nomad/issues/3454 Reliably reproduced the data race before by having a fingerprinter change the nodes attributes every millisecond and syncing at the same rate. With fix, did not ever panic. --- client/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/client.go b/client/client.go index 796d6e6ed5f8..79fbba606dce 100644 --- a/client/client.go +++ b/client/client.go @@ -501,7 +501,7 @@ func (c *Client) CollectAllAllocs() error { func (c *Client) Node() *structs.Node { c.configLock.RLock() defer c.configLock.RUnlock() - return c.config.Node + return c.configCopy.Node } // StatsReporter exposes the various APIs related resource usage of a Nomad From ea845bf7a9f0fcfe42c166db97001bb786df62a4 Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Fri, 27 Oct 2017 13:30:23 -0700 Subject: [PATCH 2/3] changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48afc2b50ec6..45808a58538d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,8 @@ BUG FIXES: [GH_-3452] * client: Fix lock contention that could cause a node to miss a heartbeat and be marked as down [GH-3195] + * client: Fix data race that could lead to concurrent map read/writes during + hearbeating and fingerprinting [GH-3461] * driver/docker: Fix docker user specified syslogging [GH-3184] * driver/docker: Fix issue where CPU usage statistics were artificially high [GH-3229] From af7e1413a5f06de2f6b02ec397d571aeba41d5c0 Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Mon, 30 Oct 2017 12:35:31 -0700 Subject: [PATCH 3/3] fix test --- client/client_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/client_test.go b/client/client_test.go index 407009de24ba..fbd49de2cf69 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -222,7 +222,7 @@ func TestClient_HasNodeChanged(t *testing.T) { c := testClient(t, nil) defer c.Shutdown() - node := c.Node() + node := c.config.Node attrHash, err := hashstructure.Hash(node.Attributes, nil) if err != nil { c.logger.Printf("[DEBUG] client: unable to calculate node attributes hash: %v", err)