konimarti / opc

OPC DA client in Golang for monitoring and analyzing process data based on Windows COM.
MIT License
237 stars 85 forks source link

Question regarding program sometimes crashes at readFromOpc #39

Closed ymmemo closed 2 years ago

ymmemo commented 2 years ago

I use readFromOpc & Read once a second asynchronously. Program sometimes crashes and irregularly.

goVersion:(go1.14.4) GOARCH:amd64
The read types include Random.Real8, Bool, Int1, String, Time, I use MatrikonOpc server for simulation.

//go-ole@v1.2.6
Exception 0xc0000005 0x0 0xc0005ad8a0 0x2a62adb3
PC=0x2a62adb3

syscall.Syscall9(0x2a62c3cc, 0x9, 0x2ac1f540, 0x60020011, 0xc0000188f0, 0x404, 0x1, 0xc0005c1648, 0xc00034a020, 0xc0005c16e8, ...)
        C:/go/src/runtime/syscall_windows.go:214 +0xf2
github.com/go-ole/go-ole.invoke(0x2ac1f540, 0x160020011, 0xc0005c1930, 0x4, 0x4, 0xc00034a020, 0x0, 0x0)
        D:/go/pkg/mod/github.com/go-ole/go-ole@v1.2.6/idispatch_windows.go:175 +0x228
github.com/go-ole/go-ole.(*IDispatch).Invoke(...)
        D:/go/pkg/mod/github.com/go-ole/go-ole@v1.2.6/idispatch.go:27
github.com/go-ole/go-ole.(*IDispatch).InvokeWithOptionalArgs(0x2ac1f540, 0xb025be, 0x4, 0x1, 0xc0005ad930, 0x4, 0x4, 0x4e8d48, 0x104ebc0, 0xaeab40)
        D:/go/pkg/mod/github.com/go-ole/go-ole@v1.2.6/idispatch.go:71 +0x103
github.com/go-ole/go-ole/oleutil.CallMethod(...)
        D:/go/pkg/mod/github.com/go-ole/go-ole@v1.2.6/oleutil/oleutil.go:51

//go-ole@v1.2.5
Exception 0xc0000005 0x0 0xc000675c48 0x2a65adb3
PC=0x2a65adb3

syscall.Syscall9(0x2a65c3cc, 0x9, 0x2adf7b30, 0x60020011, 0xc0000188f0, 0x404, 0x1, 0xc0005f1a50, 0xc000248000, 0xc0005f1af0, ...)
        C:/go/src/runtime/syscall_windows.go:214 +0xf2
github.com/go-ole/go-ole.invoke(0x2adf7b30, 0x160020011, 0xc0005f1cd8, 0x4, 0x4, 0xc000248000, 0x0, 0x0)
        D:/go/pkg/mod/github.com/go-ole/go-ole@v1.2.5/idispatch_windows.go:175 +0x229
github.com/go-ole/go-ole.(*IDispatch).Invoke(...)
        D:/go/pkg/mod/github.com/go-ole/go-ole@v1.2.5/idispatch.go:27
github.com/go-ole/go-ole.(*IDispatch).InvokeWithOptionalArgs(0x2adf7b30, 0xb02f1e, 0x4, 0x410001, 0xc000675cd8, 0x4, 0x4, 0xc000307fc0, 0x746000000000000, 0x6)
        D:/go/pkg/mod/github.com/go-ole/go-ole@v1.2.5/idispatch.go:71 +0x103
github.com/go-ole/go-ole/oleutil.CallMethod(...)
        D:/go/pkg/mod/github.com/go-ole/go-ole@v1.2.5/oleutil/oleutil.go:51
usi/dcs-adapter/internal/opclibary.(*AutomationItems).readFromOpc(0xc000833e20, 0x2adf7b30, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)

goroutine 60 [select]:
net/http.(*persistConn).writeLoop(0xc000216480)
        C:/go/src/net/http/transport.go:2277 +0x123
created by net/http.(*Transport).dialConn
        C:/go/src/net/http/transport.go:1648 +0xc82
rax     0x1d7d326befb30b0
rbx     0x0
rcx     0xffffdff3
rdi     0xc0003a1c78
rsi     0x2a9d7690
rbp     0xc0003a1c90
rsp     0x2986f860
r8      0x1826730
r9      0x7dd
r10     0x2a9d7700
r11     0xc0
r12     0xc0005e1c60
r13     0x2a889268
r14     0x2986f950
r15     0x2986f970
rip     0x2a86adb3
rflags  0x10206
cs      0x33
fs      0x53
gs      0x2b

Is this a network problem or a problem caused by COM?

hunterfaucher commented 2 years ago

Any progress on this issue? Experiencing the same

konimarti commented 2 years ago

Hey, as I mentioned in the README it is very hard to analyze your problem without having your exact configuration of automation wrapper and opc server in place. It looks like an OLE/COM issue but it would be helpful if you could share a short example program that reproduces your error.

I have never worked with the Matrikon server so I cannot comment on that. However, I use this code in production with a TANI OPC server and query hundreds of tags per second over months and never experienced this issue.

Also, why are you using the low-level readFromOpc function? If there is an issue with loading the Matrikon wrapper, let me know and we can try to include it directly in the code or implement a better interface for other wrappers.

konimarti commented 2 years ago

@ymmemo just saw that you also reported this issue on go-ole (https://github.com/go-ole/go-ole/issues/226) and it seems that a proper thread safe implementation of your asynchronuous call solved the problem. Let me know if the problem still exists and I can reopen this issue.

ymmemo commented 2 years ago

Originally, I used multiple connections to process group reading, but later changed it to one connection and lock/unlock, and the number of exceptions was reduced. Currently in testing...

lishuaia commented 2 years ago

Originally, I used multiple connections to process group reading, but later changed it to one connection and lock/unlock, and the number of exceptions was reduced. Currently in testing...

Hello, I want to ask if you have solved this problem, I also encountered this problem, I don't know how to solve it

lishuaia commented 2 years ago

Any progress on this issue? Experiencing the same

Hello, I want to ask if you have solved this problem, I also encountered this problem, I don't know how to solve it