arduino-cli icon indicating copy to clipboard operation
arduino-cli copied to clipboard

Redundant discovery processes created by additional daemon instances

Open per1234 opened this issue 3 years ago • 1 comments
trafficstars

Describe the problem

Pluggable discovery tools supply Arduino CLI with a list of "ports" of connected Arduino boards. When Arduino CLI is running as a daemon, these tools are started when a gRPC request is received that requires a port listing and then left running for the remainder of the session.

🐛 Redundant processes for each discovery tool are created by additional instances of the Arduino CLI daemon. It is possible that discovery tools may not be designed to operate correctly in this way, and the multiple processes might interfere with each other.

To reproduce

Setup

$ arduino-cli version

arduino-cli  Version: 0.29.0-rc.1 Commit: 76251df9 Date: 2022-11-17T03:35:12Z

$ arduino-cli daemon

Daemon is now listening on 127.0.0.1:50051

Demo

run the following grpcurl commands in another terminal:

$ grpcurl \
  -plaintext \
  -import-path ./rpc \
  -proto cc/arduino/cli/commands/v1/commands.proto \
  127.0.0.1:50051 \
  cc.arduino.cli.commands.v1.ArduinoCoreService.Create

{
  "instance": {
    "id": 1
  }
}

$ grpcurl \
  -plaintext \
  -import-path ./rpc \
  -proto cc/arduino/cli/commands/v1/commands.proto \
  -d '{"instance": {"id": 1}}' \
  127.0.0.1:50051 \
  cc.arduino.cli.commands.v1.ArduinoCoreService.Init

$ pgrep -a -f 'serial-discovery'  # Discovery tools have not yet been started

$ grpcurl \
  -plaintext \
  -import-path ./rpc \
  -proto cc/arduino/cli/commands/v1/commands.proto \
  -d '{"instance": {"id": 1}}' \
  127.0.0.1:50051 \
  cc.arduino.cli.commands.v1.ArduinoCoreService.BoardList

[...]

$ pgrep -a -f 'serial-discovery'  # A process for each discovery tool was created

134825 /home/per/.arduino15/packages/builtin/tools/serial-discovery/1.3.2/serial-discovery

$ grpcurl \
  -plaintext \
  -import-path ./rpc \
  -proto cc/arduino/cli/commands/v1/commands.proto \
  127.0.0.1:50051 \
  cc.arduino.cli.commands.v1.ArduinoCoreService.Create

{
  "instance": {
    "id": 2
  }
}

$ grpcurl \
  -plaintext \
  -import-path ./rpc \
  -proto cc/arduino/cli/commands/v1/commands.proto \
  -d '{"instance": {"id": 2}}' \
  127.0.0.1:50051 \
  cc.arduino.cli.commands.v1.ArduinoCoreService.Init

$ grpcurl \
  -plaintext \
  -import-path ./rpc \
  -proto cc/arduino/cli/commands/v1/commands.proto \
  -d '{"instance": {"id": 2}}' \
  127.0.0.1:50051 \
  cc.arduino.cli.commands.v1.ArduinoCoreService.BoardList

[...]

$ pgrep -a -f 'serial-discovery'

134825 /home/per/.arduino15/packages/builtin/tools/serial-discovery/1.3.2/serial-discovery
135007 /home/per/.arduino15/packages/builtin/tools/serial-discovery/1.3.2/serial-discovery

🐛 A new process is created for each discovery tool by additional Arduino CLI daemon instances.

Expected behavior

A single instance of each discovery tool should be shared by all Arduino CLI daemon instances.

Arduino CLI version

76251df9

Operating system

Windows, Ubuntu

Operating system version

Windows 10, Ubuntu 20.04

Additional context

Related: https://github.com/arduino/arduino-cli/issues/1960

Issue checklist

  • [X] I searched for previous reports in the issue tracker
  • [X] I verified the problem still occurs when using the nightly build
  • [X] My report contains all necessary details

per1234 avatar Nov 17 '22 06:11 per1234

Fixing this requires a medium refactoring of the DiscoveryManager, there is an actual real-world scenario when this could be a problem? If this is not a critical issue, I'd like to postpone it.

cmaglie avatar Feb 01 '23 10:02 cmaglie