Skip to content

Commit 5add7d9

Browse files
committed
Fix registration locking
1 parent 9cb7b99 commit 5add7d9

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

cshared.go

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ const (
3939
func FLBPluginPreRegister(hotReloading C.int) int {
4040
if hotReloading == C.int(1) {
4141
registerWG.Add(1)
42-
pluginMeta.Store(nil)
4342
}
4443

4544
return input.FLB_OK
@@ -49,46 +48,38 @@ func FLBPluginPreRegister(hotReloading C.int) int {
4948
// can be provided.
5049
//
5150
//export FLBPluginRegister
52-
func FLBPluginRegister(def unsafe.Pointer) (returnCode int) {
53-
defer func() {
54-
// Only unblock waiters on registerWG if registration succeeds
55-
if returnCode == input.FLB_OK {
56-
registerWG.Done()
57-
}
58-
}()
59-
51+
func FLBPluginRegister(def unsafe.Pointer) int {
6052
meta := pluginMeta.Load()
6153
if meta == nil {
6254
fmt.Fprintf(os.Stderr, "no input, output, or custom plugin registered\n")
6355
return input.FLB_RETRY
6456
}
6557

66-
if unregisterFunc.Load() != nil {
67-
fmt.Fprintf(os.Stderr, "plugin already registered\n")
68-
return input.FLB_ERROR
69-
}
70-
7158
var newUnregisterFunc func()
72-
59+
var registerCode int
7360
if meta.input != nil {
74-
returnCode = input.FLBPluginRegister(def, meta.name, meta.desc)
61+
registerCode = input.FLBPluginRegister(def, meta.name, meta.desc)
7562
newUnregisterFunc = func() { input.FLBPluginUnregister(def) }
7663
} else if meta.output != nil {
77-
returnCode = output.FLBPluginRegister(def, meta.name, meta.desc)
64+
registerCode = output.FLBPluginRegister(def, meta.name, meta.desc)
7865
newUnregisterFunc = func() { output.FLBPluginUnregister(def) }
7966
} else if meta.custom != nil {
80-
returnCode = custom.FLBPluginRegister(def, meta.name, meta.desc)
67+
registerCode = custom.FLBPluginRegister(def, meta.name, meta.desc)
8168
newUnregisterFunc = func() { custom.FLBPluginUnregister(def) }
8269
} else {
8370
fmt.Fprintf(os.Stderr, "no input, output, or custom plugin registered\n")
8471
return input.FLB_RETRY
8572
}
8673

87-
if returnCode == input.FLB_OK {
88-
unregisterFunc.Store(&newUnregisterFunc)
74+
if registerCode != 0 {
75+
fmt.Fprintf(os.Stderr, "error calling plugin register function\n")
76+
return input.FLB_RETRY
8977
}
9078

91-
return
79+
unregisterFunc.Store(&newUnregisterFunc)
80+
registerWG.Done()
81+
82+
return input.FLB_OK
9283
}
9384

9485
// FLBPluginInit this method gets invoked once by the fluent-bit runtime at initialisation phase.

0 commit comments

Comments
 (0)