noelex / rclnet

Modern ROS 2 client library for .NET.
MIT License
17 stars 2 forks source link

Blazor web app hangs on RclContext.CreateNode (sudden onset) #18

Closed sedwick2048 closed 3 months ago

sedwick2048 commented 3 months ago

I had my Blazor web app working fine, communicating over ROS2 via a node I initialized in the Program.cs (relevant code below). I then made a trivial change to my Razor file, and the next time I ran it, it would hang at the point where the node is created. I can create the RclContext but can't do anything with it.

      using Rcl;
      ...
      var ctx = new RclContext();
      var node = ctx.CreateNode("ROS2dotNETwebApp");                                  // Hangs here
      var pub = node.CreatePublisher<Rosidl.Messages.Example.String>("/blazor");
      var sub = node.CreateSubscription<Rosidl.Messages.Example.String>("/blazed");
      builder.Services.AddSingleton(ctx);
      builder.Services.AddSingleton(node);
      builder.Services.AddSingleton(pub);
      builder.Services.AddSingleton(sub);
      var app = builder.Build();

I even created a new Blazor web app and only added these lines (and added to launchSettings.json environmentVariables and installed the RclNet NuGet package), and it still hangs. I see an empty command window and never a home page. When I terminate the command window, Visual Studio flashes a message saying "Unable to connect to web server 'https'". If I run the Release EXE from a command window, it also hangs, and when I hit "Ctrl-C" to terminate, it displays:

[foonathan::memory] Allocator foonathan::memory::heap_allocator (at 0000000000000000) leaked 36912 bytes.

In case it's relevant, I tried solving it by running the following commands in an admin command window:

dotnet dev-certs https --clean
dotnet dev-certs https --trust

What should I now try first? Thanks...

sedwick2048 commented 3 months ago

UPDATE: I still can't explain how it started happening, but I may have stopped (most of) it. I reinstalled my Humble but that still didn't fix it; simple commands like ros2 run demo_nodes_cpp talker and ros2 topic list were still hanging. I discovered that running ros2 run demo_nodes_cpp talker --ros-args --log-level debug DID work, as did normal ros2 run demo_nodes_cpp talker afterward in the same command window, but ros2 topic list still hung. I found this and on a whim, I entered set RMW_IMPLEMENTATION=rmw_cyclonedds_cpp and then set RMW_IMPLEMENTATION=rmw_fastrtps_cpp, and amazingly, I could run the talker (and listener) normally every time in subsequent command sessions. Better, once I adjusted my launchSettings.json environmentVariablesfor the new installation paths, my Blazor web app ran fine again!

Only thing is, I still can't execute something like ros2 topic list without hanging. Oh well, different issue?...