docker-alpine icon indicating copy to clipboard operation
docker-alpine copied to clipboard

apk fetch hangs

Open dkirrane opened this issue 9 years ago • 41 comments

fetch of the apk index just hangs. I hit this now on a Ubuntu server and Docker for Windows

Step 1/14 : FROM maven:3.3.9-jdk-8-alpine
 ---> dd9d4e1cd9db
Step 2/14 : RUN apk update && apk upgrade       && apk add --no-cache --update  ca-certificates         bash    wget    curl    tree    libxml2-utils   putty   git     && rm -rf /var/lib/apt/lists/*     && rm -rf /var/cache/apk/*
 ---> Running in 536cbd484c36
fetch http://dl-cdn.alpinelinux.org/alpine/v3.5/main/x86_64/APKINDEX.tar.gz

Docker version 17.03.1-ce, build c6d412e

dkirrane avatar Jul 17 '17 09:07 dkirrane

Are you able to start another container shell and curl dl-cdn.alpinelinux.org? Sounds like a networking issue somewhere.

andyshinn avatar Jul 18 '17 18:07 andyshinn

Seems like a DNS issue. Not sure why, I've set correct dns settings in %programdata%\docker\config\daemon.json

nslookup dl-cdn.alpinelinux.org
nslookup: can't resolve '(null)': Name does not resolve

Name:      dl-cdn.alpinelinux.org
Address 1: 151.101.48.249

Got around this by running using https

RUN sed -i 's/http\:\/\/dl-cdn.alpinelinux.org/https\:\/\/alpine.global.ssl.fastly.net/g' /etc/apk/repositories

dkirrane avatar Jul 24 '17 15:07 dkirrane

Doesn't seem like a DNS issue, since it has resolved. Unfortunately, for while, I'm at the same point: names are resolved, but can't connect to anything.

charlescanato avatar Oct 04 '17 22:10 charlescanato

In another issue I thought this could be a DNS issue because the CDN POP IP addresses may change more frequently. If DNS is being cached somewhere and TTL not honored then an outdated IP address may be returned for dl-cdn.alpinelinux.org.

This is why I need debugging information to help pinpoint it. When the issue happens, I need the curl -v -s http://dl-cdn.alpinelinux.org/alpine/v3.5/main/x86_64/APKINDEX.tar.gz > /dev/null output from inside a container and the host so we can compare.

andyshinn avatar Oct 05 '17 19:10 andyshinn

Also facing this thing from time to time. Here’s a typical output of GitLab CI when fetching fails:

screen shot 2017-10-14 at 15 19 48

Manually stopping and retrying the stuck CI job helps, but there’s no guarantee of reliability

kachkaev avatar Oct 14 '17 14:10 kachkaev

/ # curl -v -s http://dl-cdn.alpinelinux.org/alpine/v3.5/main/x86_64/APKINDEX.tar.gz > /de
v/null
*   Trying 151.101.84.249...
* TCP_NODELAY set
* Connected to dl-cdn.alpinelinux.org (151.101.84.249) port 80 (#0)
> GET /alpine/v3.5/main/x86_64/APKINDEX.tar.gz HTTP/1.1
> Host: dl-cdn.alpinelinux.org
> User-Agent: curl/7.56.1
> Accept: */*
> 
< HTTP/1.1 200 OK
< Server: nginx
< Content-Type: application/octet-stream
< Last-Modified: Mon, 04 Dec 2017 09:08:18 GMT
< ETag: "5a251082-b3195"
< Accept-Ranges: bytes
< Content-Length: 733589
< Accept-Ranges: bytes
< Date: Mon, 04 Dec 2017 16:03:17 GMT
< Via: 1.1 varnish
< Connection: keep-alive
< X-Served-By: cache-bma7035-BMA
< X-Cache: MISS
< X-Cache-Hits: 0
< X-Timer: S1512403397.178165,VS0,VE64
< 
{ [8688 bytes data]
* Connection #0 to host dl-cdn.alpinelinux.org left intact
/ # 

Success while another process hangs

Step 3/12 : RUN apk add --no-cache --update     icu-dev     libxml2-dev     openldap-dev     php7-xdebug     && mv /usr/lib/php7/modules/xdebug.so /usr/local/lib/php/extensions/no-debug-non-zts-20160303     && rm -f /etc/php7/conf.d/xdebug.ini     && docker-php-ext-install     intl     ldap     soap     && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
 ---> Running in 1e9ed33cd4b3
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/main/x86_64/APKINDEX.tar.gz

One more with matching url

/ # curl -v -s http://dl-cdn.alpinelinux.org/alpine/v3.4/main/x86_64/APKINDEX.tar.gz > /de
v/null
*   Trying 151.101.84.249...
* TCP_NODELAY set
* Connected to dl-cdn.alpinelinux.org (151.101.84.249) port 80 (#0)
> GET /alpine/v3.4/main/x86_64/APKINDEX.tar.gz HTTP/1.1
> Host: dl-cdn.alpinelinux.org
> User-Agent: curl/7.56.1
> Accept: */*
> 
< HTTP/1.1 200 OK
< Server: nginx
< Content-Type: application/octet-stream
< Last-Modified: Thu, 23 Nov 2017 09:53:36 GMT
< ETag: "5a169aa0-a53fe"
< Accept-Ranges: bytes
< Content-Length: 676862
< Accept-Ranges: bytes
< Date: Mon, 04 Dec 2017 16:06:47 GMT
< Via: 1.1 varnish
< Connection: keep-alive
< X-Served-By: cache-bma7022-BMA
< X-Cache: MISS
< X-Cache-Hits: 0
< X-Timer: S1512403608.785535,VS0,VE75
< 
{ [2896 bytes data]
* Connection #0 to host dl-cdn.alpinelinux.org left intact
/ # 

antonmarin avatar Dec 04 '17 16:12 antonmarin

I ran into this issue in kubernetes. I bounced the kube-dns pod to flush any records it might be caching. This fixed the problem for me.

EDIT: Actually it didn't. Still having the problem.

andremarianiello avatar Dec 22 '17 06:12 andremarianiello

Are you running Docker-in-Docker by any chance? I have this issue only in dind containers.

unkaktus avatar Jan 12 '18 11:01 unkaktus

I only have this with dind + kubernetes. However it doesn't happen if I use '--network host' or '--net host'. I am using weave overlay network.

andremarianiello avatar Jan 12 '18 13:01 andremarianiello

@andremarianiello thanks for info, I am also using dind+kubernetes (though with flannel). Have you enabled hostNetwork: true for dind pods?

unkaktus avatar Jan 12 '18 13:01 unkaktus

@nogoegst No I haven't. It worked without doing that.

andremarianiello avatar Jan 12 '18 13:01 andremarianiello

@andremarianiello so you mean you set --network host for dockerized docker daemon? Where did you set it?

unkaktus avatar Jan 12 '18 14:01 unkaktus

I added it to my docker client commands, e.g. 'docker build --network host ...'

andremarianiello avatar Jan 12 '18 14:01 andremarianiello

I've see the k8s issue quite a bit. wireshark shows fastly getting stuck sending oversized packets with a do not fragment flag. I don't think this is OP's issue though as its docker for windows.

I recently started running into a similar issue to this as well though. On linux but the behavior is the same, apk fails fetching and mostly on the index. Again, pulled up wireshark and recreated the problem. I see things going smoothly then the apk process seems to stop ACK'ing segments from the fastly server. Fastly starts throttling and resending segments and it lags out.

I've never recreated this with curl, but it looks like apk uses a built in BSD libfetch for its HTTP communications so maybe there's a bug in there?

My network communication understanding is just enough to get me this far so here's a link to the wireshark log of the communications. hopefully an alpine dev has a better understanding and can parse out a clue or find the problem.

neclimdul avatar May 09 '18 04:05 neclimdul

It seems like fastly is filtering ICMP need to frag packets, which means that PMTU does not work. This can be a problem is your traffic goes via a network link that has MTU lower than 1500 (typically tunnels/vpns, PPPoE and similar). This can be worked around by enabling tcp mss clamping in the network.

ncopa avatar May 14 '18 19:05 ncopa

Yeah I was treating this as a different issue because it has slightly different characteristics and not the same as #279.

The Wireshark link in https://github.com/gliderlabs/docker-alpine/issues/307#issuecomment-387613710 shows a different traffic behavior. Instead of the traffic doesn't get killed at the bridge, it is never ACK'd by libfetch and Fastly's TCP session gets stuck trying to get recover. I don't know if it's even fastly's fault as on the surface it seems to be doing the right thing.

... misc traffic 
ack:                   container -> bridge -> fastly
Transmission:          container <- bridge <- fastly
Transmission:          container <- bridge <- fastly
ack:                   container -> bridge -> fastly
Transmission:          container <- bridge <- fastly
Transmission:          container <- bridge <- fastly
ack:                   container -> bridge -> fastly
Transmission:          container <- bridge <- fastly 1
Transmission:          container <- bridge <- fastly 2
Transmission:          container <- bridge <- fastly 3
Transmission:          container <- bridge <- fastly 4
Transmission:          container <- bridge <- fastly 5
... some number of other packets
Transmission:          container <- bridge <- fastly X
Transmission:          container <- bridge <- fastly 1
Transmission:          container <- bridge <- fastly 1
Transmission:          container <- bridge <- fastly 1
Transmission:          container <- bridge <- fastly 1
Transmission:          container <- bridge <- fastly 1
Transmission:          container <- bridge <- fastly 1
Transmission:          container <- bridge <- fastly 1
Transmission:          container <- bridge <- fastly 1
.... repeat

neclimdul avatar May 14 '18 20:05 neclimdul

observation, networking is hard.

neclimdul avatar May 14 '18 20:05 neclimdul

I added it to my docker client commands, e.g. 'docker build --network host ...'

where exactly did you put this? I'm facing this on kubernetes right now, where gitlab spins up a container with docker running in docker...driving me nuts for the lasst 4 hours.

evanrich avatar Oct 05 '18 04:10 evanrich

@evanrich My gitlab CI was using docker:dind as a service container, and my main build container had a docker client in it which I used to connect to the service container. My repo has a dockerfile in it that I need to be built by the gitlab runner. My .gitlab-ci.yaml file contained the command

docker build .

This builds my docker image. One of my layers in the dockerfile runs apk update. This command hangs, causing the docker build command and the CI as a whole to fail. However, if I modify my .gitlab-ci.yaml file to have

docker build --network host .

docker will run the apk update command from my dockerfile without hanging.

andremarianiello avatar Oct 05 '18 04:10 andremarianiello

I believe that the problem is that in docker the MTU is lower than on the host. The way this is supposed to work is via path MTU discovery, but fastly appears to block the PMTU icmp packet (I guess it is a part of their DDoS defence). The way to "fix" this properly is to enable MSS clamping on the host. https://blog.ipspace.net/2013/01/tcp-mss-clamping-what-is-it-and-why-do.html

The other alternative is to use a different mirror that does not block the PMTU traffic.

ncopa avatar Oct 05 '18 06:10 ncopa