From 75eccc0628d46d913dc2a291baed01b65de3b1ae Mon Sep 17 00:00:00 2001 From: Jesse Hallam Date: Tue, 2 Oct 2018 14:09:41 -0400 Subject: [PATCH] pull updates from demo plugin pr --- server/configuration.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/server/configuration.go b/server/configuration.go index cc4c8dd..15424b1 100644 --- a/server/configuration.go +++ b/server/configuration.go @@ -6,8 +6,7 @@ import ( // configuration captures the plugin's external configuration as exposed in the Mattermost server // configuration, as well as values computed from the configuration. Any public fields will be -// deserialized from the Mattermost server configuration in OnConfigurationChange, while any -// private fields will be ignored. +// deserialized from the Mattermost server configuration in OnConfigurationChange. // // As plugins are inherently concurrent (hooks being called asynchronously), and the plugin // configuration can change at any time, access to the configuration must be synchronized. The @@ -45,9 +44,18 @@ func (p *Plugin) getConfiguration() *configuration { // Do not call setConfiguration while holding the configurationLock, as sync.Mutex is not // reentrant. In particular, avoid using the plugin API entirely, as this may in turn trigger a // hook back into the plugin. If that hook attempts to acquire this lock, a deadlock may occur. +// +// This method panics if setConfiguration is called with the existing configuration. This almost +// certainly means that the configuration was modified without being cloned and may result in +// an unsafe access. func (p *Plugin) setConfiguration(configuration *configuration) { p.configurationLock.Lock() defer p.configurationLock.Unlock() + + if configuration != nil && p.configuration == configuration { + panic("setConfiguration called with the existing configuration") + } + p.configuration = configuration }