Skip to content

Long-running Stage tasks prevent SIGINT through SIGTERM type process termination #133

@brohitbrose

Description

@brohitbrose

Perhaps worth noting, though, that the Swim port (9001 in the below example) does get released, so some sort of cleanup seems to be happening.
Swim does have a shutdownhook so it is probable that the bug is in there.

Small (hopefully minimal) example:

// WastefulAgent.java
package nstream.starter;

import swim.kernel.Kernel;
import swim.server.ServerLoader;

public class WastefulAgent extends AbstractAgent {

  @Override
  public void didStart() {
    System.out.println(nodeUri() + ": didStart");
    while (true) {
      // You may wish to throttle this a bit
      System.out.println(nodeUri() + ": ping");
    }
  }

  public static void main(String[] args) {
    final Kernel kernel = ServerLoader.loadServer();
    kernel.start();
    System.out.println("Running Main ...");
    kernel.run();
  }

}
# server.recon

"starter": @fabric {
  @plane(class: "swim.api.plane.AbstractPlane")
  @node {
    uri: "/wasteful"
    @agent(class: "nstream.starter.WastefulAgent")
  }
}

@web(port: 9001) {
  space: "starter"
  @websocket {
    serverCompressionLevel: 0# -1 = default; 0 = off; 1-9 = deflate level
    clientCompressionLevel: 0# -1 = default; 0 = off; 1-9 = deflate level
  }
}

Running the main method results in an unstoppable process (outside of a kill -9 command).
This happens whether the running method is an IDE, Gradle, or a plain old Java command.
(Note that when running with Gradle, ctrl+C will seem to work, but the process is still visible w/ ps or top.)

Variations

asyncStage()

It's especially disturbing that moving the infinite loop to a proper asyncStage() call does not fix anything:

package nstream.starter;

import swim.api.agent.AbstractAgent;
import swim.concurrent.AbstractTask;

public class WastefulAgent extends AbstractAgent {

  @Override
  public void didStart() {
    System.out.println(nodeUri() + ": didStart");
    asyncStage().task(new AbstractTask() {
          @Override
          public void runTask() {
            while (true) {
              // You may wish to throttle this a bit
              System.out.println(nodeUri() + ": ping");
            }
          }
    
          @Override
          public boolean taskWillBlock() {
            return true;
          }
        })
        .cue();
  }

}

Metadata

Metadata

Labels

C-bugCategory: bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions