Init leaking memory

Bug #1756318 reported by Piotr Kruk
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
upstart
New
Undecided
Unassigned

Bug Description

Hi,

Upstart init will leak a memory, when /var/log/upstart directory was deleted from the system, and some application in init, are writing to console.

We notice this behaviour on one machine, when after 15 days, whole ram was used by process 1 (init).

After creating missing directory '/var/log/upstart', everything go to normal state.

We reproduce the situation like that:

Create silly script noisy-duck.sh
```
#!/bin/bash

while true;
do
 echo
 echo "Hello, I'm really noisy duck...."
 echo "Quack, Quack..."
 echo "Quack, Quack..."
 echo "Oops, it's (" `date` ") already. Dude, shouldn't you go for a training right now?"
 #sleep 10
done
```

And put proper configuration to /etc/init/

```
# test noisy app

description "Noisy duck"

start on filesystem or runlevel [2345]
stop on runlevel [!2345]

respawn
respawn limit 10 5
umask 022

console log

pre-start script
    test -x /usr/local/sbin/noisy-duck.sh || { stop; exit 0; }
    test -c /dev/null || { stop; exit 0; }
end script

exec /usr/local/sbin/noisy-duck.sh
```

and then 'rm -rf /var/log/upstart', and after a few hours our init process in top has a 871MB Ram usage ( you can find a screenshot in attachment)

So after running a strace -p 1, we can observe this error:

read(3, 0x7ffff457e05f, 1) = -1 EAGAIN (Resource temporarily unavailable)
waitid(P_ALL, 0, {}, WNOHANG|WEXITED|WSTOPPED|WCONTINUED, NULL) = 0
clock_gettime(CLOCK_MONOTONIC, {1208500, 693070419}) = 0
select(19, [3 5 6 7 9 10 13 14 15 16 17 18], [], [7 9 10], NULL) = 1 (in [13])
read(13, "Oops, it's ( Fri Mar 16 11:30:56"..., 8192) = 101
read(13, "\r\n\r\n", 8091) = 4
read(13, "Hello, I'm really noisy duck....", 8087) = 32
read(13, "\r\nQuack, Quack...", 8055) = 17
read(13, "\r\nQuack, Quack...\r\n", 8038) = 19
read(13, 0x7fe88cd81f3d, 8019) = -1 EAGAIN (Resource temporarily unavailable)
fstat(-1, 0x7ffff457dd10) = -1 EBADF (Bad file descriptor)
umask(0117) = 0117
open("/var/log/upstart/noisy-duck.log", O_WRONLY|O_CREAT|O_APPEND|O_NONBLOCK|O_NOFOLLOW|O_CLOEXEC, 0740) = -1 ENOENT (No such file or directory)
read(3, 0x7ffff457e05f, 1) = -1 EAGAIN (Resource temporarily unavailable)
waitid(P_ALL, 0, {}, WNOHANG|WEXITED|WSTOPPED|WCONTINUED, NULL) = 0
clock_gettime(CLOCK_MONOTONIC, {1208500, 694687321}) = 0
select(19, [3 5 6 7 9 10 13 14 15 16 17 18], [], [7 9 10], NULL) = 1 (in [13])
read(13, "Oops, it's ( Fri Mar 16 11:30:56"..., 8192) = 101
read(13, "\r\n\r\n", 8091) = 4
read(13, "Hello, I'm really noisy duck....", 8087) = 32
read(13, "\r\nQuack, Quack...", 8055) = 17
read(13, "\r\nQuack, Quack...\r\n", 8038) = 19
read(13, 0x7fe88cd81f3d, 8019) = -1 EAGAIN (Resource temporarily unavailable)
fstat(-1, 0x7ffff457dd10) = -1 EBADF (Bad file descriptor)
umask(0117) = 0117
open("/var/log/upstart/noisy-duck.log", O_WRONLY|O_CREAT|O_APPEND|O_NONBLOCK|O_NOFOLLOW|O_CLOEXEC, 0740) = -1 ENOENT (No such file or directory)

I suspect the problem is here:
https://bazaar.launchpad.net/~upstart-devel/upstart/trunk/view/head:/init/log.c#L337

Because buffor is not cleaned.
At now I'm watching this more deeply, so maybe later I will push a fix for that, but I'm curious about your opinions.

Revision history for this message
Piotr Kruk (pkruk) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Bug attachments

Remote bug watches

Bug watches keep track of this bug in other bug trackers.