From 76ba0b57a7374697e2f8ae84b84adeb73d0ab1dd Mon Sep 17 00:00:00 2001 From: Jesse Hallam Date: Thu, 15 Nov 2018 08:02:55 -0500 Subject: [PATCH] configuration: ignore an empty configuration struct in setConfiguration (#21) If the plugin leaves the configuration struct empty, go will optimize away allocations of the zero-width struct failing the `setConfiguration` check that prevents a user from introducing race conditions. --- server/configuration.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/server/configuration.go b/server/configuration.go index 15424b1..05aaf5b 100644 --- a/server/configuration.go +++ b/server/configuration.go @@ -1,6 +1,8 @@ package main import ( + "reflect" + "github.com/pkg/errors" ) @@ -53,6 +55,13 @@ func (p *Plugin) setConfiguration(configuration *configuration) { defer p.configurationLock.Unlock() if configuration != nil && p.configuration == configuration { + // Ignore assignment if the configuration struct is empty. Go will optimize the + // allocation for same to point at the same memory address, breaking the check + // above. + if reflect.ValueOf(*configuration).NumField() == 0 { + return + } + panic("setConfiguration called with the existing configuration") }