Skip to content

[1.7.0-rc2] Connection reset from published ports #13847

Closed

Description

@burke

TL;DR

Most of the comments here are just me narrowing this down to a root cause.

The root cause is that there was a stale arp table entry for 172.17.0.2, the IP of the container in question.

Also, there are duplicate iptables entries

The stale arp may be related to docker crashing earlier while I was strace'ing it.


This problem doesn't occur all of the time, as I have another host running 1.7.0 in a less demanding role with no issues. The problem may be related to a process unsuccessfully attempting to create a couple containers every second overnight (1.6.0 handles that fine).

TL;DR of below: port 5000 is bound in and outside of the container. The service responds correctly inside the container, but I just get econnreset from outside.

I don't have much time this week but I'll gather more information if I have some free moments.

[email protected]:~ 56$ docker ps | grep 5000
b6aad66a24a5        10186dca14f8a7373019edf1c049c50c10d2d40db75452fb1ee431ff55a45092   "registry cmd/regist   12 hours ago        Up 12 hours         0.0.0.0:5000->5000/tcp    borg-registry-docker-registry-1-6177
[email protected]:~ $ borg-enter b6a
root@borg-registry-docker-registry-1:/# curl localhost:5000/v2/
{}
root@borg-registry-docker-registry-1:/# logout
[email protected]:~ $ curl -vvv localhost:5000/v2/
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 5000 (#0)
> GET /v2/ HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost:5000
> Accept: */*
>
* Recv failure: Connection reset by peer
* Closing connection 0
curl: (56) Recv failure: Connection reset by peer
[email protected]:~ 56$

docker info/version/uname

Activity

  1. burke commented on Jun 10, 2015

    @burke
    ContributorAuthor

    At 15:22:06 in the capture below, I ran curl localhost:5000/v2/ in another shell.

    host:~# lsof -i :5000
    COMMAND  PID USER   FD   TYPE    DEVICE SIZE/OFF NODE NAME
    docker  7088 root    4u  IPv6 232537433      0t0  TCP *:5000 (LISTEN)
    host:~$ ps aux | grep [7]088
    root      7088  0.0  0.0 174332 13400 ?        Sl   03:01   0:00 docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 5000 -container-ip 172.17.0.2 -container-port 5000
    host:~# strace -tt -T -f -p 7088
    Process 7088 attached with 4 threads
    [pid  7091] 15:21:57.391477 futex(0xc208021258, FUTEX_WAIT, 0, NULL <unfinished ...>
    [pid  7090] 15:21:57.391507 futex(0x140f940, FUTEX_WAIT, 0, NULL <unfinished ...>
    [pid  7089] 15:21:57.391514 restart_syscall(<... resuming interrupted call ...> <unfinished ...>
    [pid  7088] 15:21:57.391556 epoll_wait(5, {{EPOLLIN, {u32=3860539272, u64=140676924385160}}}, 128, -1) = 1 <8.884238>
    [pid  7088] 15:22:06.275860 futex(0x13fc960, FUTEX_WAKE, 1) = 1 <0.000011>
    [pid  7089] 15:22:06.275895 <... restart_syscall resumed> ) = 0 <8.884377>
    [pid  7088] 15:22:06.275905 accept4(4,  <unfinished ...>
    [pid  7089] 15:22:06.275913 select(0, NULL, NULL, NULL, {0, 20} <unfinished ...>
    [pid  7088] 15:22:06.275925 <... accept4 resumed> {sa_family=AF_INET6, sin6_port=htons(36188), inet_pton(AF_INET6, "::ffff:127.0.0.1", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, [28], SOCK_CLOEXEC|SOCK_NONBLOCK) = 3 <0.000016>
    [pid  7088] 15:22:06.275955 epoll_ctl(5, EPOLL_CTL_ADD, 3, {EPOLLIN|EPOLLOUT|EPOLLRDHUP|EPOLLET, {u32=3860539080, u64=140676924384968}}) = 0 <0.000022>
    [pid  7088] 15:22:06.276000 getsockname(3,  <unfinished ...>
    [pid  7089] 15:22:06.276008 <... select resumed> ) = 0 (Timeout) <0.000084>
    [pid  7088] 15:22:06.276013 <... getsockname resumed> {sa_family=AF_INET6, sin6_port=htons(5000), inet_pton(AF_INET6, "::ffff:127.0.0.1", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, [28]) = 0 <0.000009>
    [pid  7089] 15:22:06.276023 select(0, NULL, NULL, NULL, {0, 20} <unfinished ...>
    [pid  7088] 15:22:06.276031 setsockopt(3, SOL_TCP, TCP_NODELAY, [1], 4) = 0 <0.000007>
    [pid  7088] 15:22:06.276058 accept4(4, 0xc2080dd748, [112], SOCK_CLOEXEC|SOCK_NONBLOCK) = -1 EAGAIN (Resource temporarily unavailable) <0.000009>
    [pid  7088] 15:22:06.276095 socket(PF_INET, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, IPPROTO_IP <unfinished ...>
    [pid  7089] 15:22:06.276105 <... select resumed> ) = 0 (Timeout) <0.000076>
    [pid  7088] 15:22:06.276111 <... socket resumed> ) = 6 <0.000009>
    [pid  7089] 15:22:06.276116 select(0, NULL, NULL, NULL, {0, 20} <unfinished ...>
    [pid  7088] 15:22:06.276124 setsockopt(6, SOL_SOCKET, SO_BROADCAST, [1], 4) = 0 <0.000007>
    [pid  7088] 15:22:06.276158 connect(6, {sa_family=AF_INET, sin_port=htons(5000), sin_addr=inet_addr("172.17.0.2")}, 16 <unfinished ...>
    [pid  7089] 15:22:06.276202 <... select resumed> ) = 0 (Timeout) <0.000079>
    [pid  7089] 15:22:06.276214 select(0, NULL, NULL, NULL, {0, 20} <unfinished ...>
    [pid  7088] 15:22:06.276224 <... connect resumed> ) = -1 EINPROGRESS (Operation now in progress) <0.000055>
    [pid  7088] 15:22:06.276238 epoll_ctl(5, EPOLL_CTL_ADD, 6, {EPOLLIN|EPOLLOUT|EPOLLRDHUP|EPOLLET, {u32=3860538888, u64=140676924384776}}) = 0 <0.000008>
    [pid  7088] 15:22:06.276263 epoll_wait(5, {{EPOLLIN|EPOLLOUT, {u32=3860539080, u64=140676924384968}}, {EPOLLIN|EPOLLOUT|EPOLLERR|EPOLLHUP|EPOLLRDHUP, {u32=3860538888, u64=140676924384776}}}, 128, 0) = 2 <0.000008>
    [pid  7088] 15:22:06.276290 getsockopt(6, SOL_SOCKET, SO_ERROR,  <unfinished ...>
    [pid  7089] 15:22:06.276298 <... select resumed> ) = 0 (Timeout) <0.000077>
    [pid  7088] 15:22:06.276303 <... getsockopt resumed> [111], [4]) = 0 <0.000008>
    [pid  7089] 15:22:06.276310 select(0, NULL, NULL, NULL, {0, 20} <unfinished ...>
    [pid  7088] 15:22:06.276318 epoll_ctl(5, EPOLL_CTL_DEL, 6, {0, {u32=0, u64=0}}) = 0 <0.000007>
    [pid  7088] 15:22:06.276340 close(6)    = 0 <0.000010>
    [pid  7089] 15:22:06.276393 <... select resumed> ) = 0 (Timeout) <0.000079>
    [pid  7089] 15:22:06.276405 select(0, NULL, NULL, NULL, {0, 20} <unfinished ...>
    [pid  7088] 15:22:06.276430 write(1, "time=\"2015-06-10T15:22:06Z\" leve"..., 147) = 147 <0.000008>
    [pid  7088] 15:22:06.276455 epoll_ctl(5, EPOLL_CTL_DEL, 3, {0, {u32=0, u64=0}}) = 0 <0.000007>
    [pid  7088] 15:22:06.276479 close(3 <unfinished ...>
    [pid  7089] 15:22:06.276492 <... select resumed> ) = 0 (Timeout) <0.000079>
    [pid  7089] 15:22:06.276503 select(0, NULL, NULL, NULL, {0, 20} <unfinished ...>
    [pid  7088] 15:22:06.276512 <... close resumed> ) = 0 <0.000028>
    [pid  7088] 15:22:06.276525 epoll_wait(5, {}, 128, 0) = 0 <0.000007>
    [pid  7088] 15:22:06.276546 epoll_wait(5,  <unfinished ...>
    [pid  7089] 15:22:06.276590 <... select resumed> ) = 0 (Timeout) <0.000079>
    [pid  7089] 15:22:06.276605 futex(0x13fc960, FUTEX_WAIT, 0, {60, 0}
    
  2. burke commented on Jun 10, 2015

    @burke
    ContributorAuthor

    Oh, interesting:

    $ ps aux | grep [d]ocker-proxy | grep 5000
    root      7088  0.0  0.0 174332 13400 ?        Sl   03:01   0:00 docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 5000 -container-ip 172.17.0.2 -container-port 5000
    
    $ docker inspect --format="{{.NetworkSettings.IPAddress}}" b6a
    172.17.0.2
    
    host:~$ curl 172.17.0.2:5000/v2/
    curl: (7) Failed to connect to 172.17.0.2 port 5000: Connection refused
    host:~$ curl 172.17.0.1:5000/v2/
    {}
    host:~$
    
    host:~$ ifconfig | grep 172
              inet addr:172.20.8.26  Bcast:172.20.8.255  Mask:255.255.255.0
              inet addr:172.17.42.1  Bcast:0.0.0.0  Mask:255.255.0.0
    container:~$ ifconfig | grep 172
              inet addr:172.17.0.2  Bcast:0.0.0.0  Mask:255.255.0.0
    

    I don't understand where 172.17.0.1 is coming from, or why it's able to hit the registry properly, when nothing else can.


    EDIT:

    Oh, docker just lost track of a process, probably in a crash while I was strace'ing it yesterday:

    $ ps aux |grep '[y] cmd/registry/config'
    root      7105  0.0  0.0 251632 11316 ?        Ssl  03:01   0:00 registry cmd/registry/config.yml
    root     18214  0.0  0.0 186096 11488 ?        Ssl  01:42   0:00 registry cmd/registry/config.yml
    

    So that explains why it responded on 172.17.0.1, but not why it won't respond on 172.17.0.2 even though it responds locally inside that namespace.

  3. burke commented on Jun 10, 2015

    @burke
    ContributorAuthor

    Okay, working my way outward here,

    Inside the container
    container:~# ifconfig | grep 172
              inet addr:172.17.0.2  Bcast:0.0.0.0  Mask:255.255.0.0
    container:~# curl localhost:5000/v2/
    {}
    container:~# netstat -lntp | grep 5000
    tcp6       0      0 :::5000                 :::*                    LISTEN      1/registry
    
    Host
    host:~$ ip ro get 172.17.0.2
    172.17.0.2 dev docker0  src 172.17.42.1
        cache
    host:~$ ping -qc1 172.17.0.2
    PING 172.17.0.2 (172.17.0.2) 56(84) bytes of data.
    
    --- 172.17.0.2 ping statistics ---
    1 packets transmitted, 1 received, 0% packet loss, time 0ms
    rtt min/avg/max/mdev = 0.029/0.029/0.029/0.000 ms
    host:~$ curl 172.17.0.2:5000/v2/
    curl: (7) Failed to connect to 172.17.0.2 port 5000: Connection refused
    
    iptables -L
    [email protected]:~ 3$ sudo iptables -L
    Chain INPUT (policy ACCEPT)
    target     prot opt source               destination
    
    Chain FORWARD (policy ACCEPT)
    target     prot opt source               destination
    DOCKER     all  --  anywhere             anywhere
    ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED
    ACCEPT     all  --  anywhere             anywhere
    ACCEPT     all  --  anywhere             anywhere
    
    Chain OUTPUT (policy ACCEPT)
    target     prot opt source               destination
    
    Chain DOCKER (1 references)
    target     prot opt source               destination
    ACCEPT     tcp  --  anywhere             172.17.0.3           tcp dpt:8000
    ACCEPT     tcp  --  anywhere             172.17.0.4           tcp dpt:8000
    ACCEPT     tcp  --  anywhere             172.17.0.5           tcp dpt:5000
    ACCEPT     tcp  --  anywhere             172.17.0.43          tcp dpt:8000
    ACCEPT     tcp  --  anywhere             172.17.0.2           tcp dpt:8000
    ACCEPT     tcp  --  anywhere             172.17.0.3           tcp dpt:8000
    ACCEPT     tcp  --  anywhere             172.17.0.4           tcp dpt:5000
    ACCEPT     tcp  --  anywhere             172.17.0.2           tcp dpt:8000
    ACCEPT     tcp  --  anywhere             172.17.0.3           tcp dpt:8000
    ACCEPT     tcp  --  anywhere             172.17.0.4           tcp dpt:5000
    ACCEPT     tcp  --  anywhere             172.17.0.1           tcp dpt:8000
    ACCEPT     tcp  --  anywhere             172.17.0.2           tcp dpt:5000
    ACCEPT     tcp  --  anywhere             172.17.0.1           tcp dpt:5000
    ACCEPT     tcp  --  anywhere             172.17.0.2           tcp dpt:8000
    ACCEPT     tcp  --  anywhere             172.17.0.1           tcp dpt:8000
    ACCEPT     tcp  --  anywhere             172.17.0.1           tcp dpt:8000
    ACCEPT     tcp  --  anywhere             172.17.0.2           tcp dpt:5000
    ACCEPT     tcp  --  anywhere             172.17.0.107         tcp dpt:8000
    

    Also, I stopped ufw and it didn't help the situation.

  4. burke commented on Jun 10, 2015

    @burke
    ContributorAuthor

    Pinging some people from libnetwork just because it seems likely related: @mavenugo @mrjana @aboch

    As an aside, the duplicate iptables rules are curious; I don't see those in 1.6.0.

  5. added this to the 1.7.0 milestone on Jun 10, 2015
  6. LK4D4 commented on Jun 10, 2015

    @LK4D4
    Contributor

    @burke Do you use --userland-proxy=false?

  7. jessfraz commented on Jun 10, 2015

    @jessfraz
    Contributor

    The duplicate rules is definitely a regression we had fixed that in I want to say 1.3

  8. burke commented on Jun 10, 2015

    @burke
    ContributorAuthor

    @LK4D4 We do not pass --userland-proxy=anything anywhere in our stack.

  9. LK4D4 commented on Jun 10, 2015

    @LK4D4
    Contributor

    @burke I suggest you to switch :) But probably it isn't issue(but might be!)

  10. mrjana commented on Jun 10, 2015

    @mrjana
    Contributor

    @burke The fact that

    curl 172.17.0.2:5000/v2/
    

    is failing is kind of strange. Because that should not need port forwarding at all since you are trying to reach that purely as a directly connected host.

    Trying to repro in my end but so far no luck. As you said it's probably related to those overnight smoke test that you were doing.

  11. thaJeztah commented on Jun 10, 2015

    @thaJeztah
    Member

    @jfrazelle if this is what you're talking about; added in #6950 and removed in #12437

  12. icecrime commented on Jun 10, 2015

    @icecrime
    Contributor

    This has properly been backported to libnetwork, could it be the source of the regression?

  13. mrjana commented on Jun 10, 2015

    @mrjana
    Contributor

    @icecrime The fact that @burke is getting a ECONNRESET even as a directly connected host i.e using the private 172.17.0.x IP tells us that iptable rules should not be involved in that path. Only routing via docker0. So I am not confident that duplicate rules are a root cause of this issue. This of course hinges on the fact that he is getting the same failure when he is trying to reach the container IP directly.

    @burke can you double confirm what I mentioned above. Also can you let me know what kind of overnight test that you were running in more detail so that I can try it out here?

  14. jessfraz commented on Jun 10, 2015

    @jessfraz
    Contributor

    Regardless we should not be creating duplicate rules....

  15. burke commented on Jun 10, 2015

    @burke
    ContributorAuthor

    Yes, correct, some takeaways from my troubleshooting above:

    1. The ECONNRESET is actually not related to the docker-proxy because I get ECONNREFUSED when I directly access 172.17.0.2:5000.
    2. Duplicate rules are one problem, but the connection failure is probably not iptables's fault because the behaviour does not change when I sudo stop ufw, and I don't see an iptables initscript. I'm not exactly sure how/whether ufw interacts with iptables...

    The overnight "test" is that we had 2-5 initscripts trying to start containers every second, but failing because their images were gone from the registry or something... I'm not sure precisely; this machine is just in a really unhappy state because it has a broken docker and we haven't attempted to keep it in a happy state.

  16. burke commented on Jun 10, 2015

    @burke
    ContributorAuthor

    iptables -L

    Chain INPUT (policy ACCEPT)
    target     prot opt source               destination
    
    Chain FORWARD (policy ACCEPT)
    target     prot opt source               destination
    
    Chain OUTPUT (policy ACCEPT)
    target     prot opt source               destination
    
    Chain DOCKER (0 references)
    target     prot opt source               destination
    
    # curl 172.17.0.2:5000/v2/
    curl: (7) Failed to connect to 172.17.0.2 port 5000: Connection refused
    

    And also, dunno if this is helpful, but:

    root@borg2:/home/burke# docker inspect b6a | grep 4b:a0
            "MacAddress": "02:42:4b:a0:8c:76",
    root@borg2:/home/burke# arping -Idocker0 172.17.0.2
    ARPING 172.17.0.2 from 172.17.42.1 docker0
    Unicast reply from 172.17.0.2 [02:42:4B:A0:8C:76]  0.540ms
    Unicast reply from 172.17.0.2 [02:42:D9:38:16:49]  0.548ms
    Unicast reply from 172.17.0.2 [02:42:D9:38:16:49]  0.529ms
    Unicast reply from 172.17.0.2 [02:42:D9:38:16:49]  0.528ms
    
  17. burke commented on Jun 10, 2015

    @burke
    ContributorAuthor

    And...

    root@borg2:/home/burke# arp 172.17.0.2
    Address                  HWtype  HWaddress           Flags Mask            Iface
    172.17.0.2               ether   02:42:d9:38:16:49   C                     docker0
    

    So it was just a stale ARP table line. arp -d 172.17.0.2 fixed the problem (ie. no more ECONNREFUSED, curl works correctly again), but is there some cleanup that's supposed to happen there that isn't?

  18. mrjana commented on Jun 10, 2015

    @mrjana
    Contributor

    @burke Thanks for all the info that you provided. With that we can say that there was change in the way we generate mac address which was in 1.6 based on the IP address itself while in 1.7 libnetwork implementation it can be completely random which creates those stale arp entries which affects connectivity. Working on a fix. Most likely a fix should be available in 1.7-rc3

  19. andrefreitas commented on Sep 19, 2016

    @andrefreitas

    Hi had the same problem in Docker Version 1.12.1. Cleaning the ARP entry for the Container IP fixed.

  20. thaJeztah commented on Sep 19, 2016

    @thaJeztah
    Member

    @andrefreitas please open a new issue with more details. This issue was opened with docker 1.6, and a lot has changed, so it's likely to have a different root cause (but the same effect)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions