Taskgroup shutdown when task encounters error

Hi,
I have an environment where I run a nomad taskgroup with two tasks.
There is dependancy between them where one task, called “X”, is set as Main and the other one, called “Y”,
has “Lifecycle” attribute set to “poststart”.
With the above being said, you can see that task “Y” is dependant on task “X”.
The two tasks communicate via localhost.

The problem:
When I manually “docker kill” the container of task “X” and it comes back again, the two containers (“X” and “Y”)
can no longer communicate. When accessing the two containers (via “docker exec -it”) the virtual interface that both of them saw
because they were on the same group is no longer visible on container “Y” and is only visible on container “X” after it comes back.
The issue is fixed if I also manually kill container “Y”.

I wanted to ask if nomad supports shutdown of one task when the other encounterd an error?
I.e, if container “X” was killed, I want container “Y” of the same group to be killed as well.
I checked the “Leader” attribute which I set to “true” for task “X” but it didn’t solve the issue.

Below is a snippet of an HCL file:

job "example" {
  group "task-group" {
    task "X" {
      driver = "docker"
      config {
        image        = "<some-imge-for-X>"
        network_mode = "my-user-network" # this is my user-network
        "ipv4_address": "<some-ip-from-my-user-network>"
      }
    }
    task "Y" {
      driver = "docker"
      lifecycle {
        hook    = "poststart"
      }
      config {
        image          = "<some-imge-for-Y>"
        network_mode = "container:X-${NOMAD_ALLOC_ID}"
      }
    }
  }
}

I would appreciate any advice on the matter,
Thanks in advance!
Ben Agai