After ECS_ENGINE_TASK_CLEANUP_WAIT_DURATION executes further tasks are stuck PENDING
We're using ECS with Jenkins to host "containerised" build slaves encountering an issue whereby we were running out of disk space due to the container volumes persisting following the build tasks finishing.
As #318 noted, I used the ECS_ENGINE_TASK_CLEANUP_WAIT_DURATION and set it to 1m, allowing immediate clean-up of any STOPPED container. However once this clean-up process has run any further "build" tasks Jenkins initiates, or I manually start from the ECS console, do not pass the PENDING phase? If the ECS agent is restarted on the host, build tasks start working normally again? If the ECS_ENGINE_TASK_CLEANUP_WAIT_DURATION is set longer, there are no problems with repeat build tasks until the disk becomes full or the clean-up occurs, whichever comes the sooner...
I've seen various issues such as #306 but I don't believe it is related as docker ps -a is still responsive as are all the docker commands? The only error Docker shows is immediately following the deletion of the container; I've used the jenkinsci/jnlp-slave image, just running "java -version" within the build shell script for testing:
/var/log/docker
time="2016-02-22T19:23:12.120877360Z" level=info msg="POST /v1.17/images/create?fromImage=jenkinsci%2Fjnlp-slave%3Alatest"
time="2016-02-22T19:23:14.050013409Z" level=info msg="POST /v1.17/containers/create?name=ecs-jenkins-slave-169-jenkins-slave-aedbf8b8eea8a8ef9101"
time="2016-02-22T19:23:14.615405788Z" level=info msg="GET /v1.17/containers/f4cd7b19957de83f4576af6ba9ea4265778d1b4158ed251a8a9b15088939a617/json"
time="2016-02-22T19:23:14.615852393Z" level=info msg="GET /v1.17/containers/f4cd7b19957de83f4576af6ba9ea4265778d1b4158ed251a8a9b15088939a617/json"
time="2016-02-22T19:23:14.676806603Z" level=info msg="GET /v1.17/containers/f4cd7b19957de83f4576af6ba9ea4265778d1b4158ed251a8a9b15088939a617/json"
time="2016-02-22T19:23:14.678284892Z" level=info msg="POST /v1.17/containers/f4cd7b19957de83f4576af6ba9ea4265778d1b4158ed251a8a9b15088939a617/start"
time="2016-02-22T19:23:14.848084085Z" level=info msg="GET /v1.17/containers/f4cd7b19957de83f4576af6ba9ea4265778d1b4158ed251a8a9b15088939a617/json"
time="2016-02-22T19:23:14.848359688Z" level=info msg="GET /v1.17/containers/f4cd7b19957de83f4576af6ba9ea4265778d1b4158ed251a8a9b15088939a617/json"
time="2016-02-22T19:23:14.925143168Z" level=info msg="GET /v1.17/containers/f4cd7b19957de83f4576af6ba9ea4265778d1b4158ed251a8a9b15088939a617/json"
time="2016-02-22T19:23:15.135578153Z" level=info msg="GET /v1.17/containers/f4cd7b19957de83f4576af6ba9ea4265778d1b4158ed251a8a9b15088939a617/json"
time="2016-02-22T19:23:15.135847047Z" level=info msg="GET /v1.17/containers/f4cd7b19957de83f4576af6ba9ea4265778d1b4158ed251a8a9b15088939a617/json"
time="2016-02-22T19:24:15.350773122Z" level=info msg="DELETE /v1.17/containers/f4cd7b19957de83f4576af6ba9ea4265778d1b4158ed251a8a9b15088939a617?v=1"
time="2016-02-22T19:24:15.374962339Z" level=info msg="GET /v1.17/containers/f4cd7b19957de83f4576af6ba9ea4265778d1b4158ed251a8a9b15088939a617/json"
time="2016-02-22T19:24:15.375153645Z" level=error msg="Handler for GET /v1.17/containers/f4cd7b19957de83f4576af6ba9ea4265778d1b4158ed251a8a9b15088939a617/json returned error: no such id: f4cd7b19957de83f4576af6ba9ea4265778d1b4158ed251a8a9b15088939a617"
time="2016-02-22T19:24:15.375192359Z" level=error msg="HTTP Error" err="no such id: f4cd7b19957de83f4576af6ba9ea4265778d1b4158ed251a8a9b15088939a617" statusCode=404
time="2016-02-22T19:24:15.375425912Z" level=info msg="GET /v1.17/containers/f4cd7b19957de83f4576af6ba9ea4265778d1b4158ed251a8a9b15088939a617/json"
time="2016-02-22T19:24:15.375549113Z" level=error msg="Handler for GET /v1.17/containers/f4cd7b19957de83f4576af6ba9ea4265778d1b4158ed251a8a9b15088939a617/json returned error: no such id: f4cd7b19957de83f4576af6ba9ea4265778d1b4158ed251a8a9b15088939a617"
time="2016-02-22T19:24:15.375583434Z" level=error msg="HTTP Error" err="no such id: f4cd7b19957de83f4576af6ba9ea4265778d1b4158ed251a8a9b15088939a617" statusCode=404
However the ECS Agent log is showing some errors a few minutes after the clean-up when we have stuck PENDING tasks:
/var/log/ecs/ecs-agent.log
2016-02-22T19:25:21Z [INFO] Redundant container state change for task jenkins-slave:169 arn:aws:ecs:eu-west-1:918198793645:task/004ed73e-ac5c-4d4b-ab1d-2025a615e435, Status: (STOPPED->STOPPED) Containers: [jenkins-slave (STOPPED->STOPPED),]: jenkins-slave(jenkinsci/jnlp-slave) (STOPPED->STOPPED) to STOPPED, but already STOPPED
2016-02-22T19:25:30Z [INFO] Saving state! module="statemanager"
2016-02-22T19:26:20Z [INFO] Removing container module="TaskEngine" task="jenkins-slave:169 arn:aws:ecs:eu-west-1:918198793645:task/004ed73e-ac5c-4d4b-ab1d-2025a615e435, Status: (STOPPED->STOPPED) Containers: [jenkins-slave (STOPPED->STOPPED),]" container="jenkins-slave(jenkinsci/jnlp-slave) (STOPPED->STOPPED)"
2016-02-22T19:28:30Z [INFO] No handler for message type module="ws client" type="CloseMessage"
2016-02-22T19:28:30Z [ERROR] Error getting message from ws backend module="ws client" err="unexpected EOF"
2016-02-22T19:28:30Z [INFO] Error from acs; backing off module="acs handler" err="unexpected EOF"
2016-02-22T19:28:30Z [INFO] Creating poll dialer module="ws client" host="ecs-a-2.eu-west-1.amazonaws.com"
2016-02-22T19:30:31Z [INFO] No handler for message type module="ws client" type="CloseMessage"
2016-02-22T19:30:31Z [ERROR] Error getting message from ws backend module="ws client" err="unexpected EOF"
2016-02-22T19:30:31Z [INFO] Error from acs; backing off module="acs handler" err="unexpected EOF"
2016-02-22T19:30:31Z [INFO] Creating poll dialer module="ws client" host="ecs-a-2.eu-west-1.amazonaws.com"
2016-02-22T19:33:56Z [INFO] Creating poll dialer module="ws client" host="ecs-t-2.eu-west-1.amazonaws.com"
2016-02-22T19:37:45Z [INFO] No handler for message type module="ws client" type="CloseMessage"
2016-02-22T19:37:45Z [ERROR] Error getting message from ws backend module="ws client" err="unexpected EOF"
2016-02-22T19:37:45Z [INFO] Error from acs; backing off module="acs handler" err="unexpected EOF"
2016-02-22T19:37:46Z [INFO] Creating poll dialer module="ws client" host="ecs-a-2.eu-west-1.amazonaws.com"
2016-02-22T19:43:40Z [WARN] ACS Connection hasn't had any activity for too long; closing connection module="acs hand
Following these final few messages, I'm forced to restart the agent as the cluster loses connection to it - within the console "Agent Connected" starts reporting false.
Another point to note, following a bit of testing, is that it seems the problem only materialises when the last container that uses the respective image, such as jenkinsci/jnlp-slave, is removed. For example if 5 build tasks are running and clean-up occurs, I can still launch new build tasks as long as one container that uses jenkinsci/jnlp-slave still exists; however once this is gone, no more build tasks can be launched using this image or any other of our build images until the agent is restarted...
From your description, this sounds like it might be https://github.com/aws/amazon-ecs-agent/issues/313#issuecomment-187003013. The next time you have an Agent that is acting this way, can you run docker kill -s USR1 ecs-agent and include the log file here? That should help us figure out what's going on.
Hi @samuelkarp,
Currently the issue appears like clockwork, attached is the logs; I also set "ECS_LOGLEVEL=debug" in case this provides some additional information...
Fixing this deadlock issue has been released as part of Agent v1.8.1. We also released a new AMI with the v1.8.1 agent bundled.
If you continue to run into issues or have new information, please do reopen this or a new issue. For now, I don't think we have any additional action items for this issue on our end.
@juanrhenals Thanks for a speedy resolution on this deadlocking problem. Was a real headache, but seems to be working again with the latest AMI.
@juanrhenals That was a real headache here too. We are going to update the ecs agent, thanks 😄