Skip to content

Error response from daemon: Cannot start container (fork/exec /usr/sbin/iptables: cannot allocate memory) #8539

Closed

Description

@xh3b4sd

We are running some coreos clusters. Over time (after a week) we see the following error taking place.

# systemd error log
2014/10/13 16:12:08 Error response from daemon: Cannot start container f9e42f092597e46f5cf6a507d7e70662e6ef1035a8f01d95f56c1f2934234361: iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 172.31.31.159 --dport 49450 ! -i docker0 -j DNAT --to-destination 172.17.0.95:80:  (fork/exec /usr/sbin/iptables: cannot allocate memory)

Here we need to restart the docker daemon and everything is back to normal. Is there a memory leak? I see there is enough memory available. Is it because of the swap?

environment information

# top
top - 16:13:01 up 22 days,  7:56,  1 user,  load average: 6.50, 5.44, 4.58
Tasks: 186 total,   3 running, 183 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.0%sy,  0.0%ni, 14.2%id,  1.3%wa, 33.7%hi,  0.0%si, 50.8%st
Mem:   4051204k total,  3886188k used,   165016k free,     3168k buffers
Swap:        0k total,        0k used,        0k free,  1681572k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
20318 root      20   0 3449m 1.3g  10m S    0 34.0  18:27.87 docker

# memory stats
$ free
             total       used       free     shared    buffers     cached
Mem:       4051204    3884208     166996          0       3168    1681744
-/+ buffers/cache:    2199296    1851908
Swap:            0          0          0

# coreos version
$ cat /etc/lsb-release
DISTRIB_ID=CoreOS
DISTRIB_RELEASE=410.0.0
DISTRIB_CODENAME="Red Dog"
DISTRIB_DESCRIPTION="CoreOS 410.0.0"

# docker info 
$ docker info
Containers: 22
Images: 332
Storage Driver: btrfs
Execution Driver: native-0.2
Kernel Version: 3.15.8+

# docker version
$ docker -v
Docker version 1.1.2, build d84a070

Activity

  1. dqminh commented on Oct 14, 2014

    @dqminh
    Contributor

    I think that the error here is because of the kernel prevents the go runtime from allocating more memory. Setting up a swap does help in this case ( i think it should be possible in coreos to setup a swap ).

    If it's possible, you can also test the latest 1.3 since it does have lots of improvements on memory allocations.

  2. n0rad commented on Oct 20, 2014

    @n0rad

    Same here after a full day starting / stopping / rm containers on archlinux.

    2014/10/20 20:54:22 Error response from daemon: Cannot start container d3a826e2b5a0db5005ddf4431d4f508027deb16b5532370976b732beb5535eca: iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 192.168.42.3 --dport 8000 ! -i docker0 -j DNAT --to-destination 172.17.0.75:8000:  (fork/exec /usr/sbin/iptables: cannot allocate memory)
    

    Far from full memory :

    $ free        
                 total       used       free     shared    buffers     cached
    Mem:      14364156    2021808   12342348       1304     116144     532328
    -/+ buffers/cache:    1373336   12990820
    Swap:            0          0          0
    

    But docker virtual memory is huge and close to my max memory :

    USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
    root     31858  1.5  2.4 17645784 352304 ?     Ssl  Oct19  19:12 /usr/bin/docker -d -H fd:// 
    
    $ docker --version
    Docker version 1.3.0, build c78088f
    
  3. haches commented on Oct 26, 2014

    @haches

    I'm experiencing the exact same behavior.
    Starting and removing many short-lived containers, the virtual memory after 24h is up from ~300MB to aroung 1.5GB

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
    2762 root      20   0 1532596  22976  11220 S   0.0  0.6   1:28.18 docker
    
    Docker version 1.3.0, build c78088f
    

    on Ubuntu 14.04

  4. malagant commented on Oct 26, 2014

    @malagant

    Same here. Docker 1.3.0

  5. rosskukulinski commented on Oct 26, 2014

    @rosskukulinski

    also seeing what I believe to be the same issue on CoreOS 444.5.0 w/ Docker 1.2

  6. rafikk commented on Nov 5, 2014

    @rafikk

    +1 on Docker 1.3.1

  7. denderello commented on Nov 14, 2014

    @denderello

    We have coreos cluster running and experience one outage once a week. Containers started through systemd unit files throw errors like this.

    2014/11/10 18:29:23 Error response from daemon: Cannot start container 2748d711896daadcb83fd65ba3c3cd124070013e7396060dffdeec015062697e: fork/exec /usr/bin/docker: cannot allocate memory

    Further we are getting sometimes errors like this.

    2014/11/10 19:17:00 Error response from daemon: Cannot start container 982f7a3da2dc182b61b1004d436a2cf68674ef949ab9848d4009c79094b3e592: iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 49298 ! -i docker0 -j DNAT --to-destination 172.17.1.173:6379:  (fork/exec /usr/sbin/iptables: cannot allocate memory)

    top output looks like this.

    top - 19:19:33 up 24 days,  3:49,  1 user,  load average: 1.30, 1.24, 1.16
    Tasks: 203 total,   1 running, 201 sleeping,   0 stopped,   1 zombie
    %Cpu(s):  9.7 us,  6.0 sy,  0.0 ni, 75.9 id,  7.1 wa,  1.0 hi,  0.2 si,  0.2 st
    KiB Mem:   4051192 total,  3913096 used,   138096 free,      140 buffers
    KiB Swap:        0 total,        0 used,        0 free.   187052 cached Mem
    
      PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
    28124 root      20   0 6618932 2.950g   9808 S   2.0 76.4  23:33.32 docker

    The really crazy thing is docker --debug info's output. There are only 21 containers, but 2257 goroutines! This looks really really weird and feels like there are a lot of goroutines not cleaned up correctly.

    docker --debug info
    Containers: 21
    Images: 374
    Storage Driver: btrfs
    Execution Driver: native-0.2
    Kernel Version: 3.16.2+
    Operating System: CoreOS 444.4.0
    Debug mode (server): false
    Debug mode (client): true
    Fds: 514
    Goroutines: 2257
    EventsListeners: 0
    Init SHA1: aad618defd9f41d37c64f32fb04c0f276c31bc42
    Init Path: /usr/libexec/docker/dockerinit
    

    lsof | wc -l says there are 841 open file descriptors. Docker seems to use 514 of them.

    For us it looks like the hosts memory has nothing to do with that problem, since the docker daemon always frags on another limit. It looks more likely like the daemon is getting into a unrecoverable state at some point where it cannot handle the whole container management any more. This is maybe caused by spooky goroutines. I am just thinking loud. Maybe somebody has other ideas?

    To get more and better information regarding this issue next time, which information would be cool to have to solve this problem quickly?

  8. rosskukulinski commented on Nov 14, 2014

    @rosskukulinski

    @denderello I'm curious -- do you make use of sidekicks that do docker inspect to determine the open ports of your containers? Experiencing similar problem to you on CoreOS, and I've got a hunch its related to our sidekicks. Going to run a test in our staging over the weekend to learn more.

  9. denderello commented on Nov 17, 2014

    @denderello

    @rosskukulinski: Yes, we are using sidekicks and I just had a look on how we are doing port inspection. Our approach is a bit different but could hit the same issue. Our sidekicks use docker port to determine open ports of other containers. Have you been able to run your tests?

  10. rosskukulinski commented on Nov 17, 2014

    @rosskukulinski

    Hello @denderello. I just checked in on our staging infrastructure and we had zero memory leaks over the weekend (yay!).

    Unfortunately for you, it seems that issue was not with our sidekicks, but rather our configuration of Logstash / Elastic Search. We are running a logstash global unit gathering log files from each host, shipping through redis, to another logstash for processing and archival into elastic search. On Friday I stopped those services and cycled a reboot of the cluster to start fresh. Memory utilization remained unchanged since friday afternoon when before memory use was constantly increasing.

    I'm not sure which piece of the ELK stack was causing our Docker daemons to consume all the memory, but we'll be digging into that tomorrow.

  11. denderello commented on Nov 18, 2014

    @denderello

    Cool that you could solve it in your cluster. I think we will have to go down the path of shutting down instances and take a look if maybe one specific container is causing the problems.

    If anyone else has a hint we are happy to try it out. :)

  12. dqminh commented on Nov 19, 2014

    @dqminh
    Contributor

    @denderello @rosskukulinski does the application output a lot of logs to journalctl and/or any other log processor ( i assume that since you use coreos ) ?

  13. denderello commented on Nov 21, 2014

    @denderello

    No, mostly the daemon logging that containers are stopping and starting. Already checked with journalctl --disk-usage on the nodes which looks ok. Why are you asking? Experienced any problems with large journals?

  14. dqminh commented on Nov 21, 2014

    @dqminh
    Contributor

    @denderello docker does some log buffering internally, so i observed that when the container output more logs than the consumer can consume at a time ( the easiest way would be to run yes "long string" command as an docker unit, the daemon memory consumption can increase quite a bit.

  15. calmera commented on Nov 30, 2014

    @calmera

    I'm having the same problem I think. Even without having any containers running I still get the "fork/exec /sbin/iptables: cannot allocate memory)" maybe worth mentioning I'm running docker on ARM so I have only limited memory resources to my disposal. But still I am not hitting any limits yet so it seems rather strange. Oh and my docker version is 1.3.0

  16. 108 remaining items

  17. mlaventure commented on Sep 2, 2016

    @mlaventure
    Contributor

    @jonathanperret yes, bad tab completion 😅

  18. bioothod commented on Sep 2, 2016

    @bioothod

    @jonathanperret good to know, logging will soon be resolved, thank you. This doesn't explain why in some rare cases dockerd returns memory to the system while application writing into log is still relatively active, and also what happened in the case where fork failed: it took resident memory when logging container is active

  19. jonathanperret commented on Sep 2, 2016

    @jonathanperret

    @bioothod As soon as your application writes a \n, the (1.12) log driver can write out the accumulated data and release the memory to the Go runtime; however it may take some time (seconds to minutes) for the Go runtime to release the memory to the OS, making it difficult to correlate memory usage reductions with various events such as a container exiting.

    I'm not completely sure I understand what's puzzling you in the other case (…what happened in the case where fork failed: it took resident memory when logging container is active…): how much memory is resident out of the entire memory allocated by the daemon at any point in time, depends on various factors such as how recently it was accessed and the memory pressure from other processes on the box. It does not affect the (in)ability to fork.

  20. tonistiigi commented on Sep 2, 2016

    @tonistiigi
    Member

    Closing this as the original problem of not capping the attach stream was fixed in #17877 (v1.10). There was still an issue with long log lines (#18057) that corresponds to report from @bioothod . Fix for that is in master (#22982). I've added it to 1.12.2 milestone in case there will be one.

    Thanks for all the help @jonathanperret !

  21. stszap commented on Oct 24, 2016

    @stszap

    @tonistiigi was the fix included in 1.12.2? I can still reproduce the problem in 1.12.2

  22. mlaventure commented on Oct 24, 2016

    @mlaventure
    Contributor

    @stszap it looks like it didn't make it into 1.12.2

    ping @vieux @thaJeztah is this a good candidate for 1.12.3? (Is there even enough time left to add it?)

  23. thaJeztah commented on Oct 24, 2016

    @thaJeztah
    Member

    @mlaventure @stszap we discussed cherry-picking that PR into a patch release for 1.12, but decided to keep it for 1.13 as it's not a regression in 1.12

  24. cyphar commented on Oct 25, 2016

    @cyphar
    Contributor

    @thaJeztah It's a bug that massively affects the scalability of Docker (it drastically limits the number of containers running on a server). Your call though.

  25. jmreicha commented on Nov 28, 2016

    @jmreicha

    @thaJeztah When is 1.13 scheduled to be released? What is the workaround until then?

  26. ekristen commented on Jan 26, 2017

    @ekristen
    Contributor

    Is this even fixed in 1.13? I'm seeing some interesting memory creeps and then eventually I start seeing docker top start to fail with the fork/exec error. I'm still trying to figure out where the memory creep is at.

  27. cyphar commented on Jan 26, 2017

    @cyphar
    Contributor

    @ekristen There is a series of issues within the Go runtime that can cause your memory overcommit to go to very high levels, causing OOM to kill your process (even though it isn't actually using any of the memory). Maybe that's what causing the issue? Docker has pprof endpoints to get pprof output, so you could try investigating those.

  28. wsilvan commented on Jan 28, 2017

    @wsilvan

    This error has been resolved after restart of docker daemon. It's works for me, but is intermittent

  29. cyphar commented on Jan 29, 2017

    @cyphar
    Contributor

    @wsilvan That's because restarting a process will result in getting a new address space (without any of the funky pages that the Go runtime lazy allocates). Restarting Docker will "fix" the issue, but reloading all of the containers might also drive up memory usage (causing the same issue to happen again).

  30. lpcclown commented on Jan 29, 2018

    @lpcclown

    This error has been resolved after restart of docker daemon.

    The commands are:
    sudo service docker stop

    sudo service docker start

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

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions