commit b79a019c1e68e11fb473957d52f4ce81894a9333 from: Martijn van Duren date: Tue Apr 9 12:49:10 2019 UTC Don't do event_pending check before trying to write. If we can flush multiple mails at once this can result in major contingency on the output buffer before we hit the output check commit - 1308710c42eefed9bb96098baf7016fbba862c7b commit + b79a019c1e68e11fb473957d52f4ce81894a9333 blob - 9e6511fc8dbeaf5b70d67ef9082bc18e6850f5dd blob + e522c7d28e3357f5421e4b30c01507bb1c7b64ae --- smtp_proc.c +++ smtp_proc.c @@ -371,7 +371,7 @@ smtp_vprintf(const char *fmt, va_list ap) buf.buf = reallocarray(buf.buf, buf.bufsize, sizeof(*(buf.buf))); if (buf.buf == NULL) - fatalx(NULL); + fatal(NULL); fmtlen = vsnprintf(buf.buf + buf.buflen, buf.bufsize - buf.buflen, fmt, cap); if (fmtlen == -1) @@ -394,8 +394,6 @@ smtp_write(int fd, short event, void *arg) if (buf->buflen == 0) return; - if (event_pending(&stdoutev, EV_WRITE, NULL)) - return; if (!evset) { event_set(&stdoutev, fd, EV_WRITE, smtp_write, buf); evset = 1; @@ -412,6 +410,8 @@ smtp_write(int fd, short event, void *arg) event_add(&stdoutev, NULL); } buf->buflen -= wlen; + if (buf->buflen == 0 && event_pending(&stdoutev, EV_WRITE, NULL)) + event_del(&stdoutev); } void