Skip to content
This repository was archived by the owner on Apr 10, 2025. It is now read-only.

Commit 11f67d9

Browse files
committed
Fix nginx worker 100% cpu usage (spinning on write returning EAGAIN)
Bump the pipe capacity, because running out of buffer space may cause a write to spin indefinitely on EAGAIN. Bumping the pipe capacity should eliminate the problem in practice, though in theory the module could still be subject to it. For now, leaving behind a todo with a suggested solution (should the problem ever show up again). Fixes #1380
1 parent 6f94abe commit 11f67d9

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/ngx_event_connection.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ bool NgxEventConnection::Init(ngx_cycle_t* cycle) {
5252
} else {
5353
pipe_read_fd_ = file_descriptors[0];
5454
pipe_write_fd_ = file_descriptors[1];
55+
// Attempt to bump the pipe capacity, because running out of buffer space
56+
// can potentially lead up to writes spinning on EAGAIN.
57+
// See https://github.com/pagespeed/ngx_pagespeed/issues/1380
58+
// TODO(oschaaf): Consider implementing a queueing mechanism for retrying
59+
// failed writes.
60+
fcntl(pipe_write_fd_, F_SETPIPE_SZ, 200*1024 /* minimal amount of bytes */);
5561
return true;
5662
}
5763
close(file_descriptors[0]);

0 commit comments

Comments
 (0)