Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions iocore/net/P_UnixNet.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,7 @@ check_throttle_warning()
// of emergency throttle).
//
// Hyper Emergency throttle when we are very close to exhausting file
// descriptors. Close the connection immediately, the upper levels
// will recover.
// descriptors.
//
TS_INLINE bool
check_emergency_throttle(Connection &con)
Expand All @@ -348,9 +347,9 @@ check_emergency_throttle(Connection &con)
emergency_throttle_time = Thread::get_hrtime() + (over * over) * HRTIME_SECOND;
RecSignalWarning(REC_SIGNAL_SYSTEM_ERROR, "too many open file descriptors, emergency throttling");
int hyper_emergency = fds_limit - HYPER_EMERGENCY_THROTTLE;
if (fd > hyper_emergency)
con.close();
return true;
if (fd > hyper_emergency) {
return true;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inform the caller to close the fd as we don't care the type of throttle.

}
return false;
}
Expand Down
6 changes: 2 additions & 4 deletions iocore/net/UnixNetAccept.cc
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,8 @@ NetAccept::do_blocking_accept(EThread *t)

// The con.fd may exceed the limitation of check_net_throttle() because we do blocking accept here.
if (check_emergency_throttle(con)) {
// The `con' could be closed if there is hyper emergency
if (con.fd == NO_FD) {
return 0;
}
con.close();
return 0;
}

// Use 'nullptr' to Bypass thread allocator
Expand Down
13 changes: 8 additions & 5 deletions iocore/net/UnixNetVConnection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1304,14 +1304,14 @@ UnixNetVConnection::connectUp(EThread *t, int fd)

if (check_emergency_throttle(con)) {
// The `con' could be closed if there is hyper emergency
if (con.fd == NO_FD) {
if (fd == NO_FD) {
// We need to decrement the stat because close_UnixNetVConnection only decrements with a valid connection descriptor.
NET_SUM_GLOBAL_DYN_STAT(net_connections_currently_open_stat, -1);
// Set errno force to EMFILE (reached limit for open file descriptors)
errno = EMFILE;
res = -errno;
goto fail;
}
// Set errno force to EMFILE (reached limit for open file descriptors)
errno = EMFILE;
res = -errno;
goto fail;
}

// Must connect after EventIO::Start() to avoid a race condition
Expand Down Expand Up @@ -1343,6 +1343,9 @@ UnixNetVConnection::connectUp(EThread *t, int fd)
fail:
lerrno = -res;
action_.continuation->handleEvent(NET_EVENT_OPEN_FAILED, (void *)(intptr_t)res);
if (fd != NO_FD) {
con.fd = NO_FD;
}
free(t);
return CONNECT_FAILURE;
}
Expand Down
11 changes: 8 additions & 3 deletions proxy/InkAPI.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6478,12 +6478,13 @@ TSVConn
TSVConnFdCreate(int fd)
{
UnixNetVConnection *vc;
EThread *t = this_ethread();

if (unlikely(fd == NO_FD)) {
return nullptr;
}

vc = (UnixNetVConnection *)netProcessor.allocate_vc(this_ethread());
vc = (UnixNetVConnection *)netProcessor.allocate_vc(t);
if (vc == nullptr) {
return nullptr;
}
Expand All @@ -6496,11 +6497,15 @@ TSVConnFdCreate(int fd)

vc->id = net_next_connection_number();
vc->submit_time = Thread::get_hrtime();
vc->mutex = new_ProxyMutex();
vc->set_is_transparent(false);
vc->mutex = new_ProxyMutex();
vc->set_context(NET_VCONNECTION_OUT);

if (vc->connectUp(this_ethread(), fd) != CONNECT_SUCCESS) {
// We should take the nh's lock and vc's lock before we get into the connectUp
SCOPED_MUTEX_LOCK(lock, get_NetHandler(t)->mutex, t);
SCOPED_MUTEX_LOCK(lock2, vc->mutex, t);

if (vc->connectUp(t, fd) != CONNECT_SUCCESS) {
return nullptr;
}

Expand Down