-
Notifications
You must be signed in to change notification settings - Fork 339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Data race when closing listener #357
Comments
It looks like the internal listener doesn't release the connection during the entire lifetime. Looks like a bug. func closeTrapListener(f *g.TrapListener) {
pointerVal := reflect.ValueOf(f)
val := reflect.Indirect(pointerVal)
member := val.FieldByName("finish")
if !member.IsValid() {
return
}
ptrToY := unsafe.Pointer(member.UnsafeAddr())
realPtrToY := (*int32)(ptrToY)
atomic.StoreInt32(realPtrToY, 1)
} Full example: package main
import (
"fmt"
"log"
"reflect"
"sync/atomic"
"time"
"unsafe"
"github.com/gosnmp/gosnmp"
)
func main() {
listener := gosnmp.NewTrapListener()
go func() {
fmt.Println("started")
if err := listener.Listen("0.0.0.0:2162"); err != nil {
log.Fatal(err)
}
}()
<-time.After(1 * time.Second)
fmt.Println("closed")
closeTrapListener(listener)
<-time.After(1 * time.Second)
}
func closeTrapListener(f *g.TrapListener) {
pointerVal := reflect.ValueOf(f)
val := reflect.Indirect(pointerVal)
member := val.FieldByName("finish")
if !member.IsValid() {
return
}
ptrToY := unsafe.Pointer(member.UnsafeAddr())
realPtrToY := (*int32)(ptrToY)
atomic.StoreInt32(realPtrToY, 1)
}
|
Thank you for the response, i was writing a more diligent way to handle connection with |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, I'm using this library and i get data race when i run the following program with the command:
go run -race main.go
This is the output:
Anyone had the same issue? Am i doing something wrong?
The text was updated successfully, but these errors were encountered: