Skip to content

Commit

Permalink
Merge pull request #9 from calyptia/fix-segfault
Browse files Browse the repository at this point in the history
fix segfault when thread is finalised without golang's runtime gc as …
  • Loading branch information
niedbalski authored May 12, 2022
2 parents 8493e34 + dd87125 commit 7d0d583
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
19 changes: 12 additions & 7 deletions cshared.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"log"
"os"
"reflect"
"runtime"
"time"
"unsafe"

Expand Down Expand Up @@ -124,6 +125,10 @@ func FLBPluginInputCallback(data *unsafe.Pointer, csize *C.size_t) int {
fmt.Fprintf(os.Stderr, "run: %s\n", err)
return input.FLB_ERROR
}
// enforce a runtime gc, to prevent the thread finalizer on
// fluent-bit to kick in before any remaining data has not been GC'ed
// causing a sigsegv.
defer runtime.GC()
}

return input.FLB_OK
Expand Down Expand Up @@ -252,17 +257,17 @@ func FLBPluginFlush(data unsafe.Pointer, clength C.int, ctag *C.char) int {
func FLBPluginExit() int {
log.Printf("calling FLBPluginExit(): name=%q\n", theName)

if unregister != nil {
unregister()
}

if runCancel != nil {
runCancel()
}

// if unregister != nil {
// unregister()
// }

// if theChannel != nil {
// defer close(theChannel)
// }
if theChannel != nil {
defer close(theChannel)
}

return input.FLB_OK
}
Expand Down
2 changes: 1 addition & 1 deletion plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type ConfigLoader interface {

type Message struct {
Time time.Time
Record map[string]string
Record any
tag *string
}

Expand Down

0 comments on commit 7d0d583

Please sign in to comment.