Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replicated services ignore --replicas #42741

Open
jpengenheiro opened this issue Aug 12, 2021 · 13 comments
Open

replicated services ignore --replicas #42741

jpengenheiro opened this issue Aug 12, 2021 · 13 comments

Comments

@jpengenheiro
Copy link

Description

When trying to configure a replicated service I found docker ignores the --replicas 1 and creates more than one task.

Steps to reproduce the issue:

when attempting to create the following service:

docker service create \
--mount 'type=volume,dst=/git-repo,volume-driver=local,volume-opt=type=nfs,volume-opt=device=:/my-device/sub-dir/,"volume-opt=o=addr=10.10.10.10"' \
--with-registry-auth --restart-max-attempts 0 --mode replicated-job --replicas 1 --restart-condition none \
--name git-gc --workdir /git-repo/my-repo  \
alpine/git:latest gc

Describe the results you received:

the service runs and completes, the restart conditions are honoured, however the replication is not:

docker service logs -t git-gc 
2021-08-12T11:28:49.756541188Z git-gc.0.547c729nqoxh@my-node-2    | fatal: gc is already running on machine '358c7f59552e' pid 1 (use --force if not)
2021-08-12T11:28:49.742282425Z git-gc.0.mmmmib6woho6@my-node-2    | fatal: gc is already running on machine '358c7f59552e' pid 1 (use --force if not)

despite --replicas 1, docker still creates two duplicated tasks, which leads to the service failing.

docker service ps git-gc 
ID             NAME                                   IMAGE               NODE              DESIRED STATE   CURRENT STATE             ERROR                         PORTS
uknsq9wxyy8d   git-gc.9sunyqfcz69tu76n8do1trwbs       alpine/git:latest   my-node-1         Complete        Complete 11 seconds ago                                 
547c729nqoxh   git-gc.xlgfeeokfv6wvnklxgftn8wj1       alpine/git:latest   my-node-2         Complete        Failed 12 seconds ago     "task: non-zero exit (128)"   
mmmmib6woho6    \_ git-gc.xlgfeeokfv6wvnklxgftn8wj1   alpine/git:latest   my-node-2         Complete        Failed 12 seconds ago     "task: non-zero exit (128)"

the service inspection still shows the correct parameters:

docker service inspect git-gc | jq '.[0].Spec.Mode'
{
  "ReplicatedJob": {
    "MaxConcurrent": 1,
    "TotalCompletions": 1
  }
}

Describe the results you expected:

Docker creates a single task that runs git gc.

Output of docker version:

docker version
Client: Docker Engine - Community
 Version:           20.10.7
 API version:       1.41
 Go version:        go1.13.15
 Git commit:        f0df350
 Built:             Wed Jun  2 11:56:47 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.7
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       b0f5bc3
  Built:            Wed Jun  2 11:54:58 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.6
  GitCommit:        d71fcd7d8303cbf684402823e425e9dd2e99285d
 runc:
  Version:          1.0.0-rc95
  GitCommit:        b9ee9c6314599f1b4a7f497e1f1f856fe433d3b7
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Output of docker info:

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Build with BuildKit (Docker Inc., v0.5.1-docker)
  scan: Docker Scan (Docker Inc., v0.8.0)

Server:
 Containers: 174
  Running: 8
  Paused: 0
  Stopped: 166
 Images: 26
 Server Version: 20.10.7
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: gelf
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: active
  NodeID: 9sunyqfcz69tu76n8do1trwbs
  Is Manager: true
  ClusterID: 1cc3dctx120hfd5rdmqd6oej6
  Managers: 2
  Nodes: 2
  Default Address Pool: 10.0.0.0/8  
  SubnetSize: 24
  Data Path Port: 4789
  Orchestration:
   Task History Retention Limit: 5
  Raft:
   Snapshot Interval: 10000
   Number of Old Snapshots to Retain: 0
   Heartbeat Tick: 1
   Election Tick: 10
  Dispatcher:
   Heartbeat Period: 5 seconds
  CA Configuration:
   Expiry Duration: 3 months
   Force Rotate: 0
  Autolock Managers: false
  Root Rotation In Progress: false
  Node Address: 10.35.107.97
  Manager Addresses:
   X.X.X.X:2377
   Y.Y.Y.Y:2377
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: d71fcd7d8303cbf684402823e425e9dd2e99285d
 runc version: b9ee9c6314599f1b4a7f497e1f1f856fe433d3b7
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: default
 Kernel Version: 4.19.0-16-amd64
 Operating System: Debian GNU/Linux 10 (buster)
 OSType: linux
 Architecture: x86_64
 CPUs: 4
 Total Memory: 15.67GiB
 Name: my-node-1
 ID: 7EA7:CVVU:RLTC:NE6Z:4QPV:CYY3:MYB3:456V:S2TU:IXVV:ETEV:G23D
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: No swap limit support
WARNING: Running Swarm in a two-manager configuration. This configuration provides
         no fault tolerance, and poses a high risk to lose control over the cluster.
         Refer to https://docs.docker.com/engine/swarm/admin_guide/ to configure the
         Swarm for fault-tolerance.

Additional environment details (AWS, VirtualBox, physical, etc.):

@thaJeztah
Copy link
Member

For a replicated-job, it looks like the replicas field is used to set the MaxConcurrent field (if that value is not set), so the spec (at a glance) seems to be correct. Not sure what's causing it to spin up more instances than that though;

https://github.com/docker/cli/blob/a32cd16160f1b41c1c4ae7bee4dac929d1484e59/cli/command/service/opts.go#L585-L593

	case "replicated-job":
		concurrent := options.maxConcurrent.Value()
		if concurrent == nil {
			concurrent = options.replicas.Value()
		}
		serviceMode.ReplicatedJob = &swarm.ReplicatedJob{
			MaxConcurrent:    concurrent,
			TotalCompletions: options.replicas.Value(),
		}

@dperny PTAL

@jpengenheiro
Copy link
Author

I did a little more troubleshooting with a simpler service, using an alpine image to echo hello:

docker service create \
--restart-max-attempts 0 \
--mode replicated-job \
--max-concurrent 1 \
--replicas 1 \
--restart-condition none \
--name git-gc \
--workdir /git-repo/configs_single_repo.git \
alpine:latest echo hello

It appears that the replicated job functionalities are completely ignored and docker will spin up more and more containers:

$ docker service logs git-gc | wc -l
64
$ docker service logs git-gc | wc -l
72
$ docker service logs git-gc | wc -l
76
$ docker service logs git-gc | wc -l
84
$ docker service logs git-gc | wc -l
88

I expected to find a single "hello" in my logs, instead more and more are logged until I remove the service.

help is appreciated,

thanks

@frapell
Copy link

frapell commented Jul 13, 2022

I am also hitting this issue... I need to run only 1 job, and docker is starting 2... no matter what values I use for replicas and max-concurrent, there is no way to run only 1 task...
Does anyone have a workaround while it gets solved?

I am using 20.10.17

@thaJeztah
Copy link
Member

@dperny PTAL

@nblazincic
Copy link

I have same issue here, can we have an update on this ? Thanks

@frapell
Copy link

frapell commented Mar 9, 2023

Is there work being done here? I can confirm this is still an issue with Docker 23.0.1

@batuhanfaik
Copy link

Can we update the issue label to show the current version? I can also confirm this issue with Docker Engine 23.0.1

@Vanav
Copy link

Vanav commented May 1, 2023

I can reproduce in Docker 23 if have multiple managers: replicated-job is started on every manager.
I can't reproduce in Docker 24, seems this issue is fixed (#44312).

@frapell
Copy link

frapell commented Jul 21, 2023

I can confirm this is also fixed for me now. Trying in version 24.0.4

@frapell
Copy link

frapell commented Jul 25, 2023

Trying to gather more information in order to submit a new issue, but it appears that while this particular issue is fixed, swarm starts all replicated-jobs in the same node... I am running multiple of these for a big migration, and while one node has 30 replicated-jobs started, all of the other nodes (Around 12) have none...
Is swarm not taking into account the node load when scheduling the job?

@boite
Copy link

boite commented Mar 14, 2024

We've been using Docker version 24.0.5 from the Ubuntu docker.io package, build 24.0.5-0ubuntu1~20.04.1 in swarm mode on Ubuntu 20.04 since September '23 when this version was released. In the past 14 days the behaviour of replicated-job has changed.

With a command such as the one below to create replicated-job with 1 replica, we now see two or more tasks are started instead of just one. If I constrain the service to a particular node, all tasks start on the same node:

boite@mynode-1:~$ sudo docker service create --name my_job --detach --max-concurrent 1 --secret source=env_local_2023_08_17_01,target=/app/.env.local,uid=33
,gid=33 --mode replicated-job --limit-memory 2GB --limit-cpu 2.0 --restart-condition none --with-registry-auth --constraint node.hostname==mynode-3 ghcr.io/acme/aservice:worker php /app/bin/console app:multitask:device --recency=PT3M retryFailedUploads && sudo docker service logs -ft my_job
x4uoj3h62i395aaf5ij3nl2r6
2024-03-14T11:41:21.358156432Z my_job.0.k6jie6184rjw@mynode-3    | Successfully dumped .env files in .env.local.php
2024-03-14T11:41:21.362644645Z my_job.0.vz4kwem551f1@mynode-3    | Successfully dumped .env files in .env.local.php
2024-03-14T11:41:21.775511964Z my_job.0.vz4kwem551f1@mynode-3    | 
2024-03-14T11:41:21.775567432Z my_job.0.vz4kwem551f1@mynode-3    |  I shall task 187 devices to RetryFailedUploads in batches of 10, pausing for 60 second
s between each batch.
2024-03-14T11:41:21.779584492Z my_job.0.k6jie6184rjw@mynode-3    | 
2024-03-14T11:41:21.779627370Z my_job.0.k6jie6184rjw@mynode-3    |  I shall task 187 devices to RetryFailedUploads in batches of 10, pausing for 60 second
s between each batch.
2024-03-14T11:41:21.792793554Z my_job.0.vz4kwem551f1@mynode-3    |  10 devices so far have been tasked.
2024-03-14T11:41:21.795525639Z my_job.0.k6jie6184rjw@mynode-3    |  10 devices so far have been tasked.
^C
boite@mynode-1:~$ sudo docker service rm my_job
my_job

This was working perfectly fine earlier this month - just one task would start in this scenario.

Does anyone have any clue what's wrong and how to work around it this issue?

@Vanav
Copy link

Vanav commented Apr 26, 2024

I can confirm that bug still exists. Seems it doesn't depend on version, but on some cluster state. Maybe this bug is caused by msg="error reconciling replicated job" error="uint64 underflow, we're not going to create 18446744073709551597 tasks" seen in log (bug #42742).

If cluster state is buggy, it is easy to reproduce:

# docker service create --name myjob --mode replicated-job --restart-condition none bash "true"

2ag8lwwtd3wcl45vshzj58euz
job progress: 0 out of 1 complete [>                                                  ] 
active tasks: 1 out of 1 tasks 
1/1: assigned  [====================>                              ] 
...

It will run continuously, looping starting/pending/assigned/running, but never complete, spawning more and more tasks:

# docker ps -a
CONTAINER ID   IMAGE         COMMAND                  CREATED                  STATUS                              PORTS     NAMES
53e43779a24c   bash:latest   "docker-entrypoint.s…"   Less than a second ago   Created                                       myjob.ysd2249piqpb3cr8v18dpbczf.y0jb0juujtcuo4kdgvfd2k3e9
3db544c49fd6   bash:latest   "docker-entrypoint.s…"   1 second ago             Exited (0) Less than a second ago             myjob.ysd2249piqpb3cr8v18dpbczf.yox7hqxtrbn3ulnduj4fbdwli
580c27b5b275   bash:latest   "docker-entrypoint.s…"   2 seconds ago            Exited (0) 1 second ago                       myjob.ysd2249piqpb3cr8v18dpbczf.v8duvy13ra4c0oyi1oz51zqrx
361b130dbe18   bash:latest   "docker-entrypoint.s…"   2 seconds ago            Exited (0) 1 second ago                       myjob.ysd2249piqpb3cr8v18dpbczf.pga52wq3iucwth32hgc7cpxrg
e92d0845498e   bash:latest   "docker-entrypoint.s…"   3 seconds ago            Exited (0) 2 seconds ago                      myjob.ysd2249piqpb3cr8v18dpbczf.clhez9bb4sta9xjw1fdsm8t6m
59d23f3e5058   bash:latest   "docker-entrypoint.s…"   4 seconds ago            Exited (0) 3 seconds ago                      myjob.ysd2249piqpb3cr8v18dpbczf.hbbiug1yt112riki3xzk6ot47
8f18714b43c0   bash:latest   "docker-entrypoint.s…"   4 seconds ago            Exited (0) 4 seconds ago                      myjob.ysd2249piqpb3cr8v18dpbczf.z19izhsxhuvctmkvm2umfwozt
a4492394a8e8   bash:latest   "docker-entrypoint.s…"   5 seconds ago            Exited (0) 4 seconds ago                      myjob.ysd2249piqpb3cr8v18dpbczf.2ep6t9ffwz9slm9stw2hdkgng
...

In log multiple messages are repeated:

time="2024-04-26T08:02:16.411470054+03:00" level=error msg="error reconciling replicated job" error="uint64 underflow, we're not going to create 18446744073709551597 tasks" module=orchestrator/jobs node.id=ysd2249piqpb3cr8v18dpbczf service.id=z8auktptjrnwymcofssfj04my
time="2024-04-26T08:02:16.411652728+03:00" level=error msg="error reconciling replicated job" error="uint64 underflow, we're not going to create 18446744073709551597 tasks" module=orchestrator/jobs node.id=ysd2249piqpb3cr8v18dpbczf service.id=z8auktptjrnwymcofssfj04my
time="2024-04-26T08:02:16.748834998+03:00" level=info msg="ignoring event" container=68d7d79fc521ad832f428869a54b5631f7e0dce9659940fa4639e6770570e72a module=libcontainerd namespace=moby topic=/tasks/delete type="*events.TaskDelete"
time="2024-04-26T08:02:17.361567337+03:00" level=info msg="ignoring event" container=800081b20bff536c65440ac9872302c101fa55fe97499b80003d624d318b94a4 module=libcontainerd namespace=moby topic=/tasks/delete type="*events.TaskDelete"
...

I've seen it on v25.0.3 and two manager nodes.

Workaround: demote one manager node, that has errors in log msg="error reconciling replicated job" error="uint64 underflow, we're not going to create 18446744073709551597 tasks".
After demote, only one task will be started in the test (see log below). You can promote the same node back. Maybe restart will also help. Maybe this zeros the counter of tasks so it will not overflow uint64 for some time, but will overflow again some day later?

# docker service create --name myjob --mode replicated-job --restart-condition none bash "true"

thhma8h8rbi9eduq4gcjcvjg7
job progress: 1 out of 1 complete [==================================================>] 
active tasks: 0 out of 0 tasks 
1/1: complete  [==================================================>] 
job complete

@dazinator
Copy link

@Vanav we have been hitting the same issue. Just hit it now, and when inspecting the manager nodes logs, on one of the managers I found the

time="2024-05-01T12:09:22.684811797Z" level=error msg="error reconciling replicated job" error="uint64 underflow, we're not going to create 18446744073709551603 tasks" module=orchestrator/jobs node.id=f789blco4yynmx40fjii96mh1 service.id=12g85

I don't know much about the overflow error, but I note there are some errors leading up to this event, like "the swarm does not have a leader" - it seems there was a leader re-election. I wonder if this has confused the cluster state causing one manager to run away with scheduling additional instances of the job?

Here are my logs (I have sanitised machine names, IP Addresses etc)

Note: the replicated-job that proceeded to "run away" was created at 12:08 UTC

Manager Node 3 - which is the one with the "overflow" error
Node 3 docker logs.txt

Manager Node 2
Node 2 docker logs.txt

Manager Node 1
Node 1 docker logs.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants