node-opcua: Fails to create anonymous session after reconnect

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

Current behavior After reconnect to the opc ua server the application can’t find anonymous user token policy and can’t create a new session.

Expected behavior It should be possible to lose the connection to the opc ua server and after reconnect to initialize a new session with all subscriptions.

Minimal reproduction of the problem with instructions

  1. Start atvise as opc ua server (is running as a service on windows 10 pro)
  2. Start client (following code)
  3. Stop service
  4. -> backoff Event
  5. Start service
  6. -> connection_reestablished and after_reconnection Event
  7. warning : disconnection : closing pending sessions
  8. Error: Cannot find ANONYMOUS user token policy in end point description
let options = {
    connectionStrategy: {
        maxRetry: 100000
    },
    keepSessionAlive: true
};
let client = new opcua.OPCUAClient( options );
let session : opcua.ClientSession;

client.on( "start_reconnection", function () {
    winston.info( " ... start_reconnection" );
} );
client.on( "backoff", function ( nb : any, delay : any ) {
    winston.info( "  connection failed for the", nb, " time ... We will retry in ", delay, " ms" );
} );
client.on( "connection_reestablished", function () {
    winston.info( " ... connection is reestablished after a connection break" );
} );
client.on( "after_reconnection", function ( err : Error ) {
    winston.info( " ... reconnection process has been completed: ", err );

    //without new client but with connect:
    //Error: connect already called
    //without new client and without connect:
    // "warning : disconnection : closing pending sessions" and client stops

    client = new opcua.OPCUAClient( options );
    client.connect( endpointUrl, ( err ) => {
        if ( err ) {
            let errorMsg : string = `Could not connect client: ${err}`;
            winston.error( errorMsg );
        } else {
            winston.info( "connected" );
            createOpcUaSession();
        }
    } );
} );
client.on( "timed_out_request", function ( request : any ) {
    winston.info( " ... request has timed out without receiving a response: ", request );
} );

const endpointUrl : string = 'opc.tcp://' + url + ':' + port;
winston.info( endpointUrl );

winston.info( "connect" );
client.connect( endpointUrl, ( err ) => {
    if ( err ) {
        let errorMsg : string = `Could not connect client: ${err}`;
        winston.error( errorMsg );
    } else {
        winston.info( "connected" );
        createOpcUaSession();
    }
} );

function createOpcUaSession() {
    let callback = ( err, ses ) => {
        if ( !err ) {
            winston.info( "created session" );
            session = ses;
            // this.initSubscription( session );
        } else {
            let errorMsg : string = `Could not create session: ${err}`;
            winston.error( errorMsg );
        }
    };
    winston.info( "create session" );
    client.createSession( callback );
}

Console Output:

 _info: start
info: opc.tcp://127.0.0.1:4840
info: connect
info: connected
info: create session
info: created session
info:  ... start_reconnection
info:   connection failed for the 0  time ... We will retry in  10  ms
info:   connection failed for the 1  time ... We will retry in  20  ms
info:   connection failed for the 2  time ... We will retry in  40  ms
info:   connection failed for the 3  time ... We will retry in  80  ms
info:  ... connection is reestablished after a connection break
info:  ... reconnection process has been completed: 
warning : disconnection : closing pending sessions
info: connected
info: create session
error: Could not create session: Error: Cannot find ANONYMOUS user token policy in end point description
 warning : ClientSessionKeepAliveManager#ping_server   ServiceFault returned by server { /*ServiceFault*/
 responseHeader                /* ResponseHeader                   */: {
   timeStamp                   /* UtcTime                          */: 2018-03-15T09:01:06.039Z
   requestHandle               /* IntegerId                        */: 4               0x4
   serviceResult               /* StatusCode                       */: BadSessionNotActivated (0x80270000)
   serviceDiagnostics          /* DiagnosticInfo                   */: {
     namespaceUri              /* Int32                            */: -1
     symbolicId                /* Int32                            */: -1
     locale                    /* Int32                            */: -1
     localizedText             /* Int32                            */: -1
     additionalInfo            /* String                           */: null
     innerStatusCode           /* StatusCode                       */: Good (0x00000)
     innerDiagnosticInfo       /* DiagnosticInfo                   */: {
     }
   }
   stringTable                 /* String                        [] */: [ ] (l=1)
   additionalHeader            /* ExtensionObject                  */: null
 }
};

What is the motivation / use case for changing the behavior? It should be possible to reconnect to the opc ua server.

Please tell us about your environment: For development I use atvise as opc ua server

  • ( ) I have installed node-opcua from source ( using git clone)

  • (x ) I have installed node-opcua as a package ( using npm install )

  • ( ) I am using an application that uses node-opcua

    • ( ) node-red
    • ( ) other : please specify
  • Device: Dell Precision 3510

  • OS version: 16299.309

    • (x ) Windows : version : 10 pro v1709
    • ( ) Linux : version : _________
    • ( ) MacOs : version : _________
    • ( ) Raspbian: version : _________
    • ( ) Other : specify :
  • Description of the other OPCUA system I am trying to connect to:

  • node-opcua version: `` v0.1.1-0

  • Node: node --version = v6.9.1

<bountysource-plugin>

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource. </bountysource-plugin>

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 20 (10 by maintainers)

Most upvoted comments

node-opcua version > 2.2.0 addresses reconnection issue better