question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Client only saves one callback at a time

See original GitHub issue

Description

When using a Service Client, and sending two request in a row, because the Client saves one callback at a time, only the latest is used when processing the response message from the service. (look at line 63) https://github.com/RobotWebTools/rclnodejs/blob/2e05913fb0e818f0c3a58904764ef752902a9a5e/lib/client.js#L51-L64

  • Library Version: latest develop
  • ROS Version: galactic
  • Platform / OS: Linux Ubuntu 20.04

Steps To Reproduce

Here is a minimal example that reproduces the bug (based on the example/client-example.js):


'use strict';

const rclnodejs = require('../index.js');

rclnodejs
  .init()
  .then(() => {
    const node = rclnodejs.createNode('client_example_node');

    const client = node.createClient(
      'example_interfaces/srv/AddTwoInts',
      'add_two_ints'
    );

    // First call
    client.waitForService(1000).then((result) => {
      const request = {
        a: Math.floor(1),
        b: Math.floor(2),
      };
      if (!result) {
        console.log('Error: service not available');
        // rclnodejs.shutdown();
        return;
      }
      console.log(`Sending: ${typeof request}`, request);
      client.sendRequest(request, (response) => {
        console.log(`Result1: ${typeof response}`, response);
        // rclnodejs.shutdown();
      });
    });

    // Second call
    client.waitForService(1000).then((result) => {

      const request = {
        a: Math.floor(10),
        b: Math.floor(20),
      };
      if (!result) {
        console.log('Error: service not available');
        // rclnodejs.shutdown();
        return;
      }
      console.log(`Sending: ${typeof request}`, request);
      client.sendRequest(request, (response) => {
        console.log(`Result2: ${typeof response}`, response);
        // rclnodejs.shutdown();
      });
    });

    rclnodejs.spin(node);
    setTimeout(() => {
      rclnodejs.shutdown();
    }, 1000);
  })
  .catch((e) => {
    console.log(`Error: ${e}`);
  });

Expected Behavior

The console log output should be:

Sending: object { a: 1, b: 2 }
Sending: object { a: 10, b: 20 }
Result1: object { sum: 3 }
Result2: object { sum: 30 }

Actual Behavior

Result2 is printed twice:

Sending: object { a: 1, b: 2 }
Sending: object { a: 10, b: 20 }
Result2: object { sum: 3 }
Result2: object { sum: 30 }

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
minggangwcommented, Jun 2, 2022

@ejalaa12 Yes, we should handle the response exactly as the rclcpp does, thanks for investigating the C++ implementation. For nodejs, as you said we can keep a sequence <-> callback map in my mind, and what you need is to change the following

https://github.com/RobotWebTools/rclnodejs/blob/b9ac65211cc19bd6c53a7bca6f1a59ab9591d64c/lib/node.js#L207-L214

  • L.209: passing the sequence number stored in the map.
  • L.213: passing the sequence number back to the processResponse() and letting the client find the proper callback if success is true.

I haven’t touched the code for a looong time, maybe make some mistake, just for your reference.

0reactions
minggangwcommented, Jun 6, 2022

Just submit a PR to add your names and contributions into https://github.com/RobotWebTools/rclnodejs/blob/develop/CONTRIBUTORS.md, then I will merge it

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - Callback function gets called only once
I'm writing a ZooKeeper client to monitor a node. The callback function gets called only the first time I change the data of...
Read more >
Part 5. Sharing Data Between Callbacks - Dash Plotly
One way to achieve this is by having multiple outputs for one callback: the expensive task can be done once and immediately used...
Read more >
Make your Dash App Faster with Clientside Callbacks
We'll learn to use the Dash Clientside callback to speed things up and expand access to app interactivity. View my book - The...
Read more >
IRS customer experience exec says callback trial saved ...
IRS customer experience exec says callback trial saved taxpayers 1.7M hours of hold time.
Read more >
Preventing duplicate callback requests in Amazon Connect
At the moment there is no disconnect flow for voice calls where either the agent or customer has hung up first, so we...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found