danomagnum / gologix

Ethernet/IP client library for Go inspired by pylogix that aims to be easy to use. Supports being a client and a class 3 / class 1 server.
MIT License
36 stars 11 forks source link

Concurrency issue #3

Closed gx-dt closed 1 year ago

gx-dt commented 1 year ago

Hi,

We am using this project in our company's project. When creating multiple clients by this library to read ethernet ip devices, the ioi_cache is possible to be accessed in the same time which causes the program is terminated. Is it possible to make it as a member of client structure to avoid concurrency issue?

// ioi.go
var ioi_cache map[string]*tagIOI
fatal error: concurrent map read and map write

goroutine 58 [running]:
github.com/danomagnum/gologix.(*Client).NewIOI(0xc000202140, {0xc000451080, 0x1b}, 0xca)
        /home/goProjects/pkg/mod/github.com/danomagnum/gologix@v0.10.0-!beta/ioi.go:132 +0x2d5
github.com/danomagnum/gologix.(*Client).ReadList(0xc000202140, {0xc000236000, 0x50, 0x0?}, {0xc000548410, 0x50, 0xf?})
        /home/goProjects/pkg/mod/github.com/danomagnum/gologix@v0.10.0-!beta/read.go:530 +0x1005

goroutine 8 [runnable]:
github.com/danomagnum/gologix.marshalIOIPart({0xc000451334?, 0x7?})
        /home/goProjects/pkg/mod/github.com/danomagnum/gologix@v0.10.0-!beta/ioi.go:212 +0x22b
github.com/danomagnum/gologix.(*Client).NewIOI(0xc000212820, {0xc000741160, 0x1b}, 0xca)
        /home/goProjects/pkg/mod/github.com/danomagnum/gologix@v0.10.0-!beta/ioi.go:198 +0x777
github.com/danomagnum/gologix.(*Client).ReadList(0xc000212820, {0xc000530a00, 0x50, 0x0?}, {0xc000436140, 0x50, 0xe?})
        /home/goProjects/pkg/mod/github.com/danomagnum/gologix@v0.10.0-!beta/read.go:530 +0x1005

Thank you

danomagnum commented 1 year ago

Good catch. That shouldn't be a problem. I'll try to get that changed soon.

danomagnum commented 1 year ago

Beta 11 should have this changed from a global to client local variable. Give it a try and let me know if it works.

danomagnum commented 1 year ago

Closing due to age.