High cpu usage bug in network-manager-openvpn (patch)



Hi, all

I'm using debian testing, and the version is
network-manager-openvpn-0.9.4.0.

I can connect to my openvpn server successfully, but after a while, my
CPU usage got high:

      PID USER      PRI  NI  VIRT   RES   SHR S CPU% MEM%   TIME+  Command
    11039 root       20   0 74032  3576  2932 R 100.  0.0  4:35.72 /usr/lib/NetworkManager/nm-openvpn-service

Strace shows it's repeatedly reading EOF from fd 7, 

    [pid 11039] poll([{fd=4, events=POLLIN}, {fd=3, events=POLLIN}, {fd=7, events=POLLIN}], 3, -1) = 2 ([{fd=4, revents=POLLIN}, {fd=7, revents=POLLIN}])
    [pid 11039] read(4, "\2\0\0\0\0\0\0\0", 16) = 8
    [pid 11039] write(4, "\1\0\0\0\0\0\0\0", 8) = 8
    [pid 11039] read(7, "", 1024)           = 0
    [pid 11039] write(4, "\1\0\0\0\0\0\0\0", 8) = 8
    [pid 11039] poll([{fd=4, events=POLLIN}, {fd=3, events=POLLIN}, {fd=7, events=POLLIN}], 3, -1) = 2 ([{fd=4, revents=POLLIN}, {fd=7, revents=POLLIN}])
    [pid 11039] read(4, "\2\0\0\0\0\0\0\0", 16) = 8
    [pid 11039] write(4, "\1\0\0\0\0\0\0\0", 8) = 8
    [pid 11039] read(7, "", 1024)           = 0
    [pid 11039] write(4, "\1\0\0\0\0\0\0\0", 8) = 8

which is a socket connected to localhost:1194 and in the CLOSE_WAIT
state:

    # output from "ls -l /proc/pid/fd"
    lrwx------ 1 root root 64 Oct 11 14:02 /proc/11039/fd/7 -> socket:[1024147]

    # output from "sudo netstat -a -p -n |grep 11039"
    tcp        0      0 127.0.0.1:43056         127.0.0.1:1194          CLOSE_WAIT  11039/nm-openvpn-se

My fix for this problem is to stop watching that IO channel because when
EOF occur, the poll will always return readable immediately, thus
creating busy loop.

Patch is attached, please help review.

-- 
All the best

 Bao Haojun
From 7b3ac1c3fab868a0b1655151510c132073f7f60a Mon Sep 17 00:00:00 2001
From: Bao Haojun <hjbao marvell com>
Date: Thu, 11 Oct 2012 13:36:10 +0800
Subject: [PATCH] Fix high cpu usage

When the openvpn tcp port 1194 connection is closed, poll will always
return readable immediately, thus the cpu get spinning to 100%.
---
 src/nm-openvpn-service.c |   10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/nm-openvpn-service.c b/src/nm-openvpn-service.c
index 660fd2f..d69f536 100644
--- a/src/nm-openvpn-service.c
+++ b/src/nm-openvpn-service.c
@@ -404,12 +404,20 @@ handle_management_socket (NMVPNPlugin *plugin,
 	NMOpenvpnPluginIOData *io_data = NM_OPENVPN_PLUGIN_GET_PRIVATE (plugin)->io_data;
 	gboolean again = TRUE;
 	char *str = NULL, *auth = NULL, *buf;
+	GIOStatus status;
 
 	if (!(condition & G_IO_IN))
 		return TRUE;
 
-	if (g_io_channel_read_line (source, &str, NULL, NULL, NULL) != G_IO_STATUS_NORMAL)
+	status = g_io_channel_read_line (source, &str, NULL, NULL, NULL);
+
+	if (status != G_IO_STATUS_NORMAL) {
+		if (status == G_IO_STATUS_EOF && io_data->socket_channel_eventid) {
+			g_source_remove (io_data->socket_channel_eventid);
+			io_data->socket_channel_eventid = 0;
+		}
 		return TRUE;
+	}
 
 	if (strlen (str) < 1)
 		goto out;
-- 
1.7.10.4



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]