RobotWebTools / roslibjs

The Standard ROS JavaScript Library
https://robotwebtools.github.io/roslibjs
Other
660 stars 373 forks source link

Question about client genertated by Service donnot disconnected when node exit #567

Closed byebaibai closed 1 year ago

byebaibai commented 1 year ago

Description

Steps To Reproduce

setInterval(function () {
  var statusRos = new ROSLIB.Ros();
  statusRos.connect(that.$rosBackendUrl);
  statusRos.getNodes(async function (nodes) {
    for(var ni in nodes) {
      const device_status_client = new ROSLIB.Service({
        ros: statusRos,
        name: "foo/get_device_status",
        serviceType: 'std_srvs/Empty'
      })
      async function getStatus() {
        return new Promise((resolve, reject) => {
          device_status_client.callService(
            new ROSLIB.ServiceRequest({}), 
            device => {
              // Do something
              resolve();
            },
            error => {
              reject(error);
              console.error(error);
            }
          );
        })
      }
      try {
        await getStatus();
      } catch( err ){
        console.error(err);
      }
    }
  }
  await statusRos.close();
}, 1000);

Expected Behavior When using kill -2 {NODE_PID} to exit one node, the client caused by callService should be disconnected to the rosbridge_websocket, and the number of clients connected to the rosbridge_websocket should be minus one.

Actual Behavior When using kill -2 {NODE_PID} to exit one node, the client caused by callService seems not to be disconnected to the rosbridge_websocket, and the number of clients connected to the rosbridge_websocket should hold the same.

MatthijsBurgh commented 1 year ago

@byebaibai could you create a running example?

MatthijsBurgh commented 1 year ago

The ROS object is disconnecting. Not the topics/service. So something else is going wrong.