Skip to content
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

Telegraf OPCUA runtime error: invalid memory address or nil pointer dereference #9164

Closed
Tracked by #10062
jeffsparks opened this issue Apr 21, 2021 · 9 comments · Fixed by #11539
Closed
Tracked by #10062

Telegraf OPCUA runtime error: invalid memory address or nil pointer dereference #9164

jeffsparks opened this issue Apr 21, 2021 · 9 comments · Fixed by #11539
Assignees
Labels
area/opcua bug unexpected problem or unintended behavior

Comments

@jeffsparks
Copy link

Relevant telegraf.conf:

[[inputs.opcua]]
 name = "opcus-TEST"
 endpoint = "opc.tcp://10.9.192.2:49310"
 connect_timeout = "10s"
 request_timeout = "5s"
 security_policy = "Basic256Sha256"
 security_mode = "SignAndEncrypt"
 certificate = "/etc/telegraf/cert.pem"
 private_key = "/etc/telegraf/key.pem"
 auth_method = "UserName"
 username = "telegraf-user"
 password = "telegraf-password"
 nodes = [
  {name="datetime_test", namespace="0", identifier_type="i", identifier="F1002LPN_Filler1.PLC_Admin.PLCDateTime_005", data_type="int",description="test"}
 ]

System info:

Telegraf 1.18.1
Ubuntu Server

Docker

Steps to reproduce:

  1. Modified the /etc/telegraf/telegraf.conf to match above
  2. Configured endpoint in server (correct port, sign and encrypt)
  3. Generated key and certificate
  4. Trusted certificate on server
  5. Run sudo telegraf --config /etc/telegraf/telegraf.conf

Expected behavior:

Full disclaimer: I haven't got it to work yet, but due to error message I don't think it is related to my configuration

Actual behavior:

jeff@ubuntu-server:~$ sudo telegraf --config /etc/telegraf/telegraf.conf
2021-04-21T14:19:53Z I! Starting Telegraf 1.18.1
2021-04-21T14:19:53Z I! Loaded inputs: cpu disk diskio kernel mem opcua processes swap system
2021-04-21T14:19:53Z I! Loaded aggregators:
2021-04-21T14:19:53Z I! Loaded processors:
2021-04-21T14:19:53Z I! Loaded outputs: influxdb_v2
2021-04-21T14:19:53Z I! Tags enabled: host=ubuntu-server
2021-04-21T14:19:53Z I! [agent] Config: Interval:10s, Quiet:false, Hostname:"ubuntu-server", Flush Interval:10s
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1a11bf2]

goroutine 51 [running]:
github.com/gopcua/opcua/ua.(*NodeID).Encode(0x0, 0x39a5a00, 0x0, 0x7fe56d37fac0, 0x0, 0x0)
/go/pkg/mod/github.com/gopcua/[email protected]/ua/node_id.go:398 +0x52
github.com/gopcua/opcua/ua.encode(0x39a5a00, 0xc000010770, 0x196, 0xc000545980, 0x2b, 0xc000010770, 0x196, 0x8, 0xc000c615b8, 0x30e314b)
/go/pkg/mod/github.com/gopcua/[email protected]/ua/encode.go:46 +0xccf
github.com/gopcua/opcua/ua.writeSlice(0x32e05c0, 0xc00024d928, 0x197, 0xc000545950, 0x28, 0x457814, 0x28, 0xc000545950, 0x28, 0xc000545950)
/go/pkg/mod/github.com/gopcua/[email protected]/ua/encode.go:131 +0x2ea
github.com/gopcua/opcua/ua.encode(0x32e05c0, 0xc00024d928, 0x197, 0xc000545950, 0x28, 0xc00024d928, 0x197, 0xc000545950, 0x28, 0x0)
/go/pkg/mod/github.com/gopcua/[email protected]/ua/encode.go:85 +0xa87
github.com/gopcua/opcua/ua.writeStruct(0x36a1980, 0xc00024d920, 0x199, 0x31102e0, 0x18, 0x3506d38, 0x203000, 0x307c368, 0x203000, 0x306dc23)
/go/pkg/mod/github.com/gopcua/[email protected]/ua/encode.go:99 +0x258
github.com/gopcua/opcua/ua.encode(0x36a1980, 0xc00024d920, 0x199, 0x31102e0, 0x18, 0x199, 0x465dd3, 0x3471f00, 0x0, 0xc0002f41a0)
/go/pkg/mod/github.com/gopcua/[email protected]/ua/encode.go:83 +0xb31
github.com/gopcua/opcua/ua.encode(0x3506d00, 0xc00024d920, 0x16, 0x31102e0, 0x18, 0xc000c616c8, 0x4, 0xc000c616e0, 0x7fe56d3987a0, 0xc000bd5808)
/go/pkg/mod/github.com/gopcua/[email protected]/ua/encode.go:81 +0x993
github.com/gopcua/opcua/ua.Encode(0x3506d00, 0xc00024d920, 0xc00024d920, 0x0, 0x0, 0x0, 0x4)
/go/pkg/mod/github.com/gopcua/[email protected]/ua/encode.go:34 +0x118
github.com/gopcua/opcua/ua.(*Buffer).WriteStruct(0xc000bd5958, 0x3506d00, 0xc00024d920)
/go/pkg/mod/github.com/gopcua/[email protected]/ua/buffer.go:306 +0x67
github.com/gopcua/opcua/uasc.(*Message).Encode(0xc00024d9a0, 0x428ed88, 0xc00024d920, 0xc000000004, 0xc000c243c0, 0x12a05f200)
/go/pkg/mod/github.com/gopcua/[email protected]/uasc/message.go:125 +0x136
github.com/gopcua/opcua/uasc.(*SecureChannel).sendAsyncWithTimeout(0xc0002ed8c0, 0x428ed88, 0xc00024d920, 0xc000000004, 0xc000c12120, 0xc000c243c0, 0x1a3d301, 0x12a05f200, 0xc000c243c0, 0x12a05f200, ...)
/go/pkg/mod/github.com/gopcua/[email protected]/uasc/secure_channel.go:701 +0x133
github.com/gopcua/opcua/uasc.(*SecureChannel).sendRequestWithTimeout(0xc0002ed8c0, 0x428ed88, 0xc00024d920, 0x4, 0xc000c12120, 0xc000c243c0, 0x12a05f200, 0xc000bd5c90, 0x0, 0x0)
/go/pkg/mod/github.com/gopcua/[email protected]/uasc/secure_channel.go:622 +0xb7
github.com/gopcua/opcua/uasc.(*SecureChannel).SendRequestWithTimeout(0xc0002ed8c0, 0x428ed88, 0xc00024d920, 0xc000c243c0, 0x12a05f200, 0xc000bd5c90, 0x8, 0x3506d80)
/go/pkg/mod/github.com/gopcua/[email protected]/uasc/secure_channel.go:681 +0xcf
github.com/gopcua/opcua.(*Client).sendWithTimeout(0xc00057a850, 0x428ed88, 0xc00024d920, 0x12a05f200, 0xc000bd5c90, 0x410a38, 0x20)
/go/pkg/mod/github.com/gopcua/[email protected]/client.go:451 +0xbb
github.com/gopcua/opcua.(*Client).Send(...)
/go/pkg/mod/github.com/gopcua/[email protected]/client.go:437
github.com/gopcua/opcua.(*Client).RegisterNodes(0xc00057a850, 0xc00024d920, 0xc000bc6240, 0x0, 0x0)
/go/pkg/mod/github.com/gopcua/[email protected]/client.go:552 +0x8f
github.com/influxdata/telegraf/plugins/inputs/opcua.Connect(0xc000442c00, 0x0, 0x0)
/go/src/github.com/influxdata/telegraf/plugins/inputs/opcua/opcua_client.go:410 +0x315
github.com/influxdata/telegraf/plugins/inputs/opcua.(*OpcUA).Gather(0xc000442c00, 0x42ddd18, 0xc00056a040, 0x34, 0x0)
/go/src/github.com/influxdata/telegraf/plugins/inputs/opcua/opcua_client.go:503 +0x56c
github.com/influxdata/telegraf/models.(*RunningInput).Gather(0xc0005ba870, 0x42ddd18, 0xc00056a040, 0x2ee6000, 0x7ffff000)
/go/src/github.com/influxdata/telegraf/models/running_input.go:117 +0x6d
github.com/influxdata/telegraf/agent.(*Agent).gatherOnce.func1(0xc00050f440, 0xc0005ba870, 0x42ddd18, 0xc00056a040)
/go/src/github.com/influxdata/telegraf/agent/agent.go:491 +0x3f
created by github.com/influxdata/telegraf/agent.(*Agent).gatherOnce
/go/src/github.com/influxdata/telegraf/agent/agent.go:490 +0xb2

Additional info:

I havne't gotten the OPCUA plugin to work yet but I tried various combinations of settings to confirm it isn't simple configuration error. I think the issue might originate in the gopcua but I will look into it.

@jeffsparks jeffsparks added the bug unexpected problem or unintended behavior label Apr 21, 2021
@sjwang90
Copy link
Contributor

sjwang90 commented Nov 8, 2021

@jeffsparks @henjoe Can you both test with the latest version of Telegraf.

Looks like #9551 #9524 #9583 have all been merged since this issue was opened.

@henjoe
Copy link

henjoe commented Nov 8, 2021

Hello Thanks for this.
Will try to test it.

@jeffsparks
Copy link
Author

I will test again but it will take a few days

@magiconair
Copy link

I think the only way this can panic at https://github.com/gopcua/opcua/blob/v0.1.13/ua/node_id.go#L396-L398 is if the node id is nil. n.mask will then panic.

@magiconair
Copy link

Maybe something going wrong in RegisterNodes ?

@magiconair
Copy link

I would suggest to not register nodes unless you know that it is supported by the OPC/UA server and that you can handle the auto-reconnect case where the session might invalidate the registered node id. In any case, registered reads are performance optimization for very high-volume, very high-frequency reads and not needed IMHO for normal data collection.

See gopcua/opcua#557 and gopcua/opcua#478

@magiconair
Copy link

Also, please test this with the latest gopcua version which at this moment is v0.3.1. It is very different from v0.1.13

@arnold256
Copy link

arnold256 commented Jun 14, 2022

Any update on this issue. I am using telegraf v1.23.0 and have attempted to connect to the GE iFix OPC UA Server and Kepware both of which produce this error.

*Edit
This was a problem with my config I had set the identifier_type="i" and was using a string identifier. It works correctly now.

*Edit
Looking at the config file above it has the same issue.
{name="datetime_test", namespace="0", identifier_type="i", identifier="F1002LPN_Filler1.PLC_Admin.PLCDateTime_005", data_type="int",description="test"}
Should be
{name="datetime_test", namespace="0", identifier_type="s", identifier="F1002LPN_Filler1.PLC_Admin.PLCDateTime_005", data_type="int",description="test"}

@prczsf
Copy link

prczsf commented Jul 19, 2022

Any update on this issue. I am using telegraf v1.23.0 and have attempted to connect to the GE iFix OPC UA Server and Kepware both of which produce this error.

Yes. Same issue.
My kepware is 6.12.325 (Latest Version), and telegraf 1.23.2.
The identifier_type="s" is collected while identifier_type="i" is invalid memory address errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/opcua bug unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants