summaryrefslogtreecommitdiffstats
path: root/modules/process
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2021-02-03 22:36:38 +0100
committerGitHub <noreply@github.com>2021-02-03 22:36:38 +0100
commit87009ab40a905b6f7d267f71434fda2a32725c57 (patch)
tree6a5d8ad96aa3f1457d70040395f25f30bc49121d /modules/process
parent0d1444751f755c624ffb4c56cb0020ce7a083c77 (diff)
downloadgitea-87009ab40a905b6f7d267f71434fda2a32725c57.tar.gz
gitea-87009ab40a905b6f7d267f71434fda2a32725c57.zip
Reduce data races (#14549)
* Add race conditions into test * Fix Race in GetManager() * DataAsync() use error chan * just log no chan * finish
Diffstat (limited to 'modules/process')
-rw-r--r--modules/process/manager.go5
-rw-r--r--modules/process/manager_test.go9
2 files changed, 12 insertions, 2 deletions
diff --git a/modules/process/manager.go b/modules/process/manager.go
index 27ed1d4964..9d57f4eb7b 100644
--- a/modules/process/manager.go
+++ b/modules/process/manager.go
@@ -25,6 +25,7 @@ var (
// ErrExecTimeout represent a timeout error
ErrExecTimeout = errors.New("Process execution timeout")
manager *Manager
+ managerInit sync.Once
// DefaultContext is the default context to run processing commands in
DefaultContext = context.Background()
@@ -48,11 +49,11 @@ type Manager struct {
// GetManager returns a Manager and initializes one as singleton if there's none yet
func GetManager() *Manager {
- if manager == nil {
+ managerInit.Do(func() {
manager = &Manager{
processes: make(map[int64]*Process),
}
- }
+ })
return manager
}
diff --git a/modules/process/manager_test.go b/modules/process/manager_test.go
index 42f4b0c04b..a515fc32cd 100644
--- a/modules/process/manager_test.go
+++ b/modules/process/manager_test.go
@@ -12,6 +12,15 @@ import (
"github.com/stretchr/testify/assert"
)
+func TestGetManager(t *testing.T) {
+ go func() {
+ // test race protection
+ _ = GetManager()
+ }()
+ pm := GetManager()
+ assert.NotNil(t, pm)
+}
+
func TestManager_Add(t *testing.T) {
pm := Manager{processes: make(map[int64]*Process)}