node-opcua: await session.read() for single node returns error in 0.2.0

I’m submitting a … (check one with “x”)

Current behavior

When performing a read on a single node (using async/await without callback as described here), an error is thrown.

Expected behavior

A value is returned.

Minimal reproduction of the problem with instructions

const opcua = require('node-opcua')

let endpointUrl = 'opc.tcp://localhost:53530/OPCUA/SimulationServer'
let client = new opcua.OPCUAClient({
  connectionStrategy: {
    maxRetry: 3,
    initialDelay: 1000,
    maxDelay: 10000
  },
  keepSessionAlive: true
})

;(async () => {
  await client.connect(endpointUrl)
  let session = await client.createSession()

  let datavalues = await session.read([{ nodeId: 'ns=5;s=Sinusoid1' }]) // works as expected
  console.log(datavalues)

  let datavalue = await session.read({ nodeId: 'ns=5;s=Sinusoid1' }) // throws an error
  console.log(datavalue)
})()

Please tell us about your environment:

MacOS 10.13

  • Description of the other OPCUA system I am trying to connect to:

    • Name:Prosys Simulation OPCUA Server
    • Version:2.3.2
    • Manufacturer/Software vendor: Prosys
  • node-opcua version: `` 0.2.0

  • Node: node --version = v8.9.0

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 15 (7 by maintainers)

Most upvoted comments

@erossignon With the example program above I still get the error. I’ll include it this time:

ERROR !!! , please check here !!!! callback may be called twice !!  TypeError: Cannot read property '0' of null
    at ./node_modules/node-opcua-client/src/client_session.js:804:96
    at ./node_modules/node-opcua-client/src/client_session.js:1157:9
    at modified_callback (./node_modules/node-opcua-secure-channel/src/client/client_secure_channel_layer.js:986:28)
    at process_request_callback (./node_modules/node-opcua-secure-channel/src/client/client_secure_channel_layer.js:76:5)
    at ClientSecureChannelLayer._on_message_received (./node_modules/node-opcua-secure-channel/src/client/client_secure_channel_layer.js:122:5)
    at emitMany (events.js:147:13)
    at MessageBuilder.emit (events.js:224:7)
    at MessageBuilder._decode_message_body (./node_modules/node-opcua-secure-channel/src/message_builder.js:442:22)
    at MessageBuilderBase._feed_messageChunk (./node_modules/node-opcua-transport/src/message_builder_base.js:192:18)
    at PacketAssembler.<anonymous> (./node_modules/node-opcua-transport/src/message_builder_base.js:52:14)
(node:13882) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot read property '0' of null
(node:13882) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

The error originates from line 804 where callback(…) is called, but I can’t figure out what the difference is between the read() call with or without an array. From line 764 onwards, the logic seems to be the same for both cases?

OK Found it ! I manage to reproduce with Prosys Demo server. The issue comes from diagnostic info to nul in the response string. It is already fixed in master branch , fix will be in next pacth