Is there a way to make `consul lock` skip critical nodes?

Hello.

I’m trying to use consul lock to execute a service on a single node:

consul lock \
    -name simple-loop \
    -verbose service/simple-loop/leader \
    "/bin/bash -c 'while true; do echo "$(date --rfc-3339=seconds): OK"; sleep 5; done'"

I starts that command on 2 nodes

node1:~# consul lock -name simple-loop -verbose service/simple-loop/leader "/bin/bash -c 'while true; do echo "$(date --rfc-3339=seconds): OK"; sleep 5; done'"
Setting up lock at path: service/simple-loop/leader/.lock
Attempting lock acquisition
Starting handler
2023-01-10 09:11:46+01:00: OK
2023-01-10 09:11:46+01:00: OK
2023-01-10 09:11:46+01:00: OK
2023-01-10 09:11:46+01:00: OK
^CShutdown triggered, killing child
Terminating child pid 108842
Error running handler: signal: terminated
Child terminated
Cleanup succeeded
node2:~# consul lock -name simple-loop -verbose service/simple-loop/leader "/bin/bash -c 'while true; do echo "$(date --rfc-3339=seconds): OK"; sleep 5; done'"
Setting up lock at path: service/simple-loop/leader/.lock
Attempting lock acquisition
Starting handler
2023-01-10 09:11:56+01:00: OK
2023-01-10 09:11:56+01:00: OK
^CShutdown triggered, killing child
Terminating child pid 130571
Error running handler: signal: terminated
Child terminated
Cleanup succeeded

I have a simple node check which is passing for node1 and critical for node2.

As we can see in the previous output, when I abort the process on node1, it starts automatically on node2.

Is there a way to skip node2, which has a critical check, when the lock is released on node1?

Regards.

According to session documentation, the session should be invalidated if Any of the health checks go to the critical state.

I wonder why it doesn’t work with consul lock.

The check is failling:

curl -s http://127.0.0.1:8500/v1/agent/checks | jq .
{
  "my_node_check": {
    "Node": "node2",
    "CheckID": "my_node_check",
    "Name": "my_node_check",
    "Status": "critical",
    "Notes": "",
    "Output": "",
    "ServiceID": "",
    "ServiceName": "",
    "ServiceTags": [],
    "Type": "",
    "Interval": "10s",
    "Timeout": "1s",
    "ExposedPort": 0,
    "Definition": {},
    "CreateIndex": 0,
    "ModifyIndex": 0
  }
}

The node2 has the consul lock session:

curl -s http://localhost:8500/v1/session/node/node2 | jq .
[
  {
    "ID": "c544ba98-c18d-dcd6-d7ef-fdf7a74a061d",
    "Name": "simple-loop",
    "Node": "node2",
    "LockDelay": 15000000000,
    "Behavior": "release",
    "TTL": "15s",
    "NodeChecks": [
      "serfHealth"
    ],
    "ServiceChecks": null,
    "CreateIndex": 275126,
    "ModifyIndex": 275126
  }
]