[ 
https://issues.apache.org/jira/browse/MESOS-9221?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16632651#comment-16632651
 ] 

Chun-Hung Hsiao edited comment on MESOS-9221 at 9/28/18 11:45 PM:
------------------------------------------------------------------

Typically, Mesos containerizer pulls a blob in 5 steps:
1. {{curl -o <blob> <blob-uri>}}.
2. After getting a 401, do {{curl -i <blob-uri>}} to get the authentication 
challenge.
3. Do a {{curl -i <auth-server-uri>}} to get the token.
4. Do a {{curl -w "%\{http_code\}\n%\{redirect_url\}" -o <blob> -H 
<auth-token-header> <blob-uri>}}
5. After getting a 307, do {{curl -o <blob> <redirect-url>}} to fetch the blob.

The original hypothesis mentioned in the description is that the error json 
stored in the blob was generated by Step 4.
However, in this case, a failure would have been returned and the associated 
docker store promise would have become terminal, which was not what we observed.
Also, currently Docker's auth server returns tokens that expire in 300 seconds, 
which even make the original hypothesis hard to trigger.

A much more probable hypothesis is that the error json was generated by Step 1.
After that, one of Steps 2--4 was stalled, possibly due to a network issue.


I'm able to reproduce the same symptom in Mesos 1.5 with the following setting:

1. Run a private Docker registry locally:
{noformat}
$ docker run --rm -p5000:5000 registry
{noformat}

2. Push an image into the private registry:
{noformat}
$ docker pull chhsiao/alpine
$ docker tag chhsiao/alpine localhost:5000/alpine
$ docker push localhost:5000/alpine
{noformat}

3. Run an Nginx proxy for the registry with config [^nginx_registry.conf]:
{noformat}
$ docker run --rm -p80:80 --net=host 
--mount=type=bind,source=`pwd`/nginx_registry.conf,target=/etc/nginx/nginx.conf 
nginx:perl
{noformat}
This config does the following:
a) Any visits to {{/v2/}} without a proper auth header will get a 401 with an 
auth challenge.
b) The Nginx server serves the challenge through {{/token}}.
c) Any fetch for the last layer will be pending forever even with a proper auth 
header.

4. Start a local Mesos master and agent with Docker support enabled:
{noformat}
$ sudo bin/mesos-master.sh --work_dir=$HOME/var/lib/mesos
{noformat}
{noformat}
$ sudo bin/mesos-agent.sh --work_dir=$HOME/var/lib/mesos 
--master=<master-ip>:5050 --image_providers=docker 
--isolation=filesystem/linux,docker/runtime
{noformat}
5. Run a UCR task with task info  [^mesos-task.json]:
{noformat}
$ src/mesos-execute --master=<master-ip>:5050 --task=$HOME/mesos-task.json
WARNING: Logging before InitGoogleLogging() is written to STDERR
W0928 16:06:53.719611  8251 parse.hpp:116] Specifying an absolute filename to 
read a command line option out of without using 'file:// is deprecated and will 
be removed in a future release. Simply adding 'file://' to the beginning of the 
path should eliminate this warning.
I0928 16:06:53.750340  8263 scheduler.cpp:188] Version: 1.5.1
I0928 16:06:53.756285  8267 scheduler.cpp:311] Using default 'basic' HTTP 
authenticatee
I0928 16:06:53.757665  8270 scheduler.cpp:494] New master detected at 
master@<master-ip>:5050
Subscribed with ID 365f595c-2970-4571-8cdb-b542696038d1-0004
Submitted task 'test' to agent 'fc1cb8d5-2ac4-44d6-bcb3-15dd0afbdacf-S1'
{noformat}

6 This task will be pending forever, even after the executor registration 
timeout is reached:
{noformat}
I0928 16:07:53.809486 29186 slave.cpp:6816] Terminating executor 'test-1' of 
framework 365f595c-2970-4571-8cdb-b542696038d1-0004 because it did not register 
within 1mins
I0928 16:07:53.809718 29175 containerizer.cpp:2365] Destroying container 
2e8738a2-c043-45bf-a0d3-57c2e0157c94 in PROVISIONING state
I0928 16:07:53.809880 29175 containerizer.cpp:2979] Transitioning the state of 
container 2e8738a2-c043-45bf-a0d3-57c2e0157c94 from PROVISIONING to DESTROYING
{noformat}
{noformat}
$ curl -q http://<master-ip>:5050/state | jq .
...
          "id": "test-1",
          "name": "test",
          "framework_id": "365f595c-2970-4571-8cdb-b542696038d1-0004",
          "executor_id": "",
          "slave_id": "fc1cb8d5-2ac4-44d6-bcb3-15dd0afbdacf-S1",
          "state": "TASK_STAGING",
...
{noformat}
And the docker store staging dir still exists:
{noformat}
$ sudo cat 
/tmp/mesos/store/docker/staging/JD9vi2/sha256:4fe2ade4980c2dda4fc95858ebb981489baec8c1e4bd282ab1c3560be8ff9bde
{"errors":[{"code":"UNAUTHORIZED","message":"authentication required"}]}
{noformat}

7. If we terminate {{mesos-execute}} and start a new one to launch another 
task, no additional HTTP request will be logged by the Nginx server.

8. Once the Nginx server is stopped, the docker store staging directory will be 
cleaned up:
{noformat}
$ sudo cat 
/tmp/mesos/store/docker/staging/JD9vi2/sha256:4fe2ade4980c2dda4fc95858ebb981489baec8c1e4bd282ab1c3560be8ff9bde
cat: 
/tmp/mesos/store/docker/staging/JD9vi2/sha256:4fe2ade4980c2dda4fc95858ebb981489baec8c1e4bd282ab1c3560be8ff9bde:
 No such file or directory
{noformat}

If this issue is indeed caused by a pending {{curl}} command, then this is 
already resolved by https://issues.apache.org/jira/browse/MESOS-8620.


was (Author: chhsia0):
Typically, Mesos containerizer pulls a blob in 5 steps:
1. {{curl -o <blob> <blob-uri>}}.
2. After getting a 401, do {{curl -i <blob-uri>}} to get the authentication 
challenge.
3. Do a {{curl -i <auth-server-uri>}} to get the token.
4. Do a {{curl -w "%\{http_code\}\n%\{redirect_url\}" -o <blob> -H 
<auth-token-header> <blob-uri>}}
5. After getting a 307, do {{curl -o <blob> <redirect-url>}} to fetch the blob.

The original hypothesis mentioned in the description is that the error json 
stored in the blob was generated by Step 4.
However, in this case, a failure would have been returned and the associated 
docker store promise would have become terminal, which was not what we observed.
Also, currently Docker's auth server returns tokens that expire in 300 seconds,
which even make the original hypothesis hard to trigger.

A much more probable hypothesis is that the error json was generated by Step 1.
After that, one of Steps 2--4 was stalled, possibly due to a network issue.


I'm able to reproduce the same symptom in Mesos 1.5 with the following setting:

1. Run a private Docker registry locally:
{noformat}
$ docker run --rm -p5000:5000 registry
{noformat}

2. Push an image into the private registry:
{noformat}
$ docker pull chhsiao/alpine
$ docker tag chhsiao/alpine localhost:5000/alpine
$ docker push localhost:5000/alpine
{noformat}

3. Run an Nginx proxy for the registry with config [^nginx_registry.conf]:
{noformat}
$ docker run --rm -p80:80 --net=host 
--mount=type=bind,source=`pwd`/nginx_registry.conf,target=/etc/nginx/nginx.conf 
nginx:perl
{noformat}
This config does the following:
a) Any visits to {{/v2/}} without a proper auth header will get a 401 with an 
auth challenge.
b) The Nginx server serves the challenge through {{/token}}.
c) Any fetch for the last layer will be pending forever even with a proper auth 
header.

4. Start a local Mesos master and agent with Docker support enabled:
{noformat}
$ sudo bin/mesos-master.sh --work_dir=$HOME/var/lib/mesos
{noformat}
{noformat}
$ sudo bin/mesos-agent.sh --work_dir=$HOME/var/lib/mesos 
--master=<master-ip>:5050 --image_providers=docker 
--isolation=filesystem/linux,docker/runtime
{noformat}
5. Run a UCR task with task info  [^mesos-task.json]:
{noformat}
$ src/mesos-execute --master=<master-ip>:5050 --task=$HOME/mesos-task.json
WARNING: Logging before InitGoogleLogging() is written to STDERR
W0928 16:06:53.719611  8251 parse.hpp:116] Specifying an absolute filename to 
read a command line option out of without using 'file:// is deprecated and will 
be removed in a future release. Simply adding 'file://' to the beginning of the 
path should eliminate this warning.
I0928 16:06:53.750340  8263 scheduler.cpp:188] Version: 1.5.1
I0928 16:06:53.756285  8267 scheduler.cpp:311] Using default 'basic' HTTP 
authenticatee
I0928 16:06:53.757665  8270 scheduler.cpp:494] New master detected at 
master@<master-ip>:5050
Subscribed with ID 365f595c-2970-4571-8cdb-b542696038d1-0004
Submitted task 'test' to agent 'fc1cb8d5-2ac4-44d6-bcb3-15dd0afbdacf-S1'
{noformat}

6 This task will be pending forever, even after the executor registration 
timeout is reached:
{noformat}
I0928 16:07:53.809486 29186 slave.cpp:6816] Terminating executor 'test-1' of 
framework 365f595c-2970-4571-8cdb-b542696038d1-0004 because it did not register 
within 1mins
I0928 16:07:53.809718 29175 containerizer.cpp:2365] Destroying container 
2e8738a2-c043-45bf-a0d3-57c2e0157c94 in PROVISIONING state
I0928 16:07:53.809880 29175 containerizer.cpp:2979] Transitioning the state of 
container 2e8738a2-c043-45bf-a0d3-57c2e0157c94 from PROVISIONING to DESTROYING
{noformat}
{noformat}
$ curl -q http://<master-ip>:5050/state | jq .
...
          "id": "test-1",
          "name": "test",
          "framework_id": "365f595c-2970-4571-8cdb-b542696038d1-0004",
          "executor_id": "",
          "slave_id": "fc1cb8d5-2ac4-44d6-bcb3-15dd0afbdacf-S1",
          "state": "TASK_STAGING",
...
{noformat}
And the docker store staging dir still exists:
{noformat}
$ sudo cat 
/tmp/mesos/store/docker/staging/JD9vi2/sha256:4fe2ade4980c2dda4fc95858ebb981489baec8c1e4bd282ab1c3560be8ff9bde
{"errors":[{"code":"UNAUTHORIZED","message":"authentication required"}]}
{noformat}

7. If we terminate {{mesos-execute}} and start a new one to launch another 
task, no additional HTTP request will be logged by the Nginx server.

8. Once the Nginx server is stopped, the docker store staging directory will be 
cleaned up:
{noformat}
$ sudo cat 
/tmp/mesos/store/docker/staging/JD9vi2/sha256:4fe2ade4980c2dda4fc95858ebb981489baec8c1e4bd282ab1c3560be8ff9bde
cat: 
/tmp/mesos/store/docker/staging/JD9vi2/sha256:4fe2ade4980c2dda4fc95858ebb981489baec8c1e4bd282ab1c3560be8ff9bde:
 No such file or directory
{noformat}

If this issue is indeed caused by a pending {{curl}} command, then this is 
already resolved by https://issues.apache.org/jira/browse/MESOS-8620.

> If some image layers are large, the image pulling may stuck due to the 
> authorized token expired.
> ------------------------------------------------------------------------------------------------
>
>                 Key: MESOS-9221
>                 URL: https://issues.apache.org/jira/browse/MESOS-9221
>             Project: Mesos
>          Issue Type: Bug
>          Components: containerization
>    Affects Versions: 1.5.0
>            Reporter: Gilbert Song
>            Assignee: Chun-Hung Hsiao
>            Priority: Major
>              Labels: containerizer
>         Attachments: mesos-task.json, nginx_registry.conf
>
>
> The image layer blobs pulling happen asynchronously but in the same 
> libprocess process. There is a chance that one layer get the token then the 
> thread switch to another layer curling which may take long. When the original 
> layer curling resumes, the token already expired (e.g., after 60 seconds).
> {noformat}
> $ sudo cat 
> /var/lib/mesos/slave/store/docker/staging/0gx64f/sha256\:c75480ad9aafadef6c7faf829ede40cf2fa990c9308d6cd354d53041b01a7cda
> {"errors":[{"code":"UNAUTHORIZED","message":"authentication 
> required","detail":[{"Type":"repository","Class":"","Name":"mesosphere/dapis","Action":"pull"}]}]}
> {noformat}
> The impact is the task launch stuck and all subsequent task using this image 
> would also stuck because it waits for the same image pulling future to become 
> ready.
> Please note that this issue is not likely to be reproduced, unless on a busy 
> system using images containing large layers.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to