Re: 100% CPU usage
"Ryan O'Hara" <[email protected]>
| Newsgroups | gmane.linux.keepalived.devel |
|---|---|
| Message-ID | <[email protected]> |
On Mon, Jun 10, 2013 at 11:59:51AM +0300, Pasi Kärkkäinen wrote: > On Thu, Jun 06, 2013 at 09:11:15PM +0100, John Sullivan wrote: > > On Thursday, June 6, 2013, 2:55:25 PM, Graeme Fowler wrote: > > > It seems that your mail server is the culprit. I don't fully understand why - a couple of messages get out, then a bunch of connectons get stuck: > > > > Not convinced the keepalived smtp engine is right here. > > > > > On 6 Jun 2013, at 12:12, Rimbalza Rimbalza <[email protected]> wrote: > > >> The log file contains these 3 repeating lines forever. > > >> 1530 13:08:46.986966 read(14, "", 512) = 0 > > >> 1530 13:08:46.986993 read(13, "", 512) = 0 > > >> 1530 13:08:46.987021 select(1024, [4 6 11 13 14], [], [], {0, 62960}) = 2 (in [13 14], left {0, 62958}) > > >> 1530 13:08:46.987090 read(14, "", 512) = 0 > > >> 1530 13:08:46.987117 read(13, "", 512) = 0 > > >> 1530 13:08:46.987145 select(1024, [4 6 11 13 14], [], [], {0, 62836}) = 2 (in [13 14], left {0, 62834}) > > > > Check out keepalived/core/smtp.c, smtp_read_thread(). > > > > It does the read, checks for -1 - mostly error conditions except > > for EAGAIN which, on a non-blocking socket, simply means no data > > is available *yet* but the socket is still good. > > > > Otherwise it assumes it got some data, appends it to the buffer, > > parses for the status code etc., requeues the select for read. > > > > At no point does it check for a zero return from read(), which > > means the socket has been closed by the other end (or otherwise > > failed). On a closed socket (where all input has already been > > drained), read() will *always* return immediately with 0, and > > select() will always indicate readability, hence the spin. > > > > Wanna send a patch? :) I've attached a quick-and-dirty patch. Note that I have not completely tested this patch because I am unable to easily recreate the problem. Comments welcome. Ryan ------------------------------------------------------------------------------ This SF.net email is sponsored by Windows: Build for Windows Store. http://p.sf.net/sfu/windows-dev2dev _______________________________________________ Keepalived-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/keepalived-devel
smtp_read_thread.patch
(text/plain, 611 B)
diff --git a/keepalived/core/smtp.c b/keepalived/core/smtp.c
index e74a0a5..7bfb5f1 100644
--- a/keepalived/core/smtp.c
+++ b/keepalived/core/smtp.c
@@ -167,8 +167,8 @@ smtp_read_thread(thread_t * thread)
rcv_buffer_size = read(thread->u.fd, buffer + smtp->buflen,
SMTP_BUFFER_LENGTH - smtp->buflen);
- if (rcv_buffer_size == -1) {
- if (errno == EAGAIN)
+ if (rcv_buffer_size <= 0) {
+ if (rcv_buffer_size == -1 && errno == EAGAIN)
goto end;
log_message(LOG_INFO, "Error reading data from remote SMTP server [%s]:%d."
, inet_sockaddrtos(&global_data->smtp_server), SMTP_PORT);