mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-03-02 23:18:44 +00:00
Enter meltdown mode if ProgramMaxWorkers triggers
This commit is contained in:
parent
9c06067c84
commit
c9d7838213
2 changed files with 11 additions and 5 deletions
|
@ -741,10 +741,10 @@ FUNCTIONS
|
|||
|
||||
Turns Lua data structure into JSON string.
|
||||
|
||||
Since Lua uses tables are both hashmaps and arrays, we use a
|
||||
simple fast algorithm for telling the two apart. Tables with
|
||||
non-zero length (as reported by `#`) are encoded as arrays,
|
||||
and any non-array elements are ignored. For example:
|
||||
Since Lua tables are both hashmaps and arrays, we use a simple
|
||||
fast algorithm for telling the two apart. Tables with non-zero
|
||||
length (as reported by `#`) are encoded as arrays, and any
|
||||
non-array elements are ignored. For example:
|
||||
|
||||
>: EncodeJson({2})
|
||||
"[2]"
|
||||
|
|
|
@ -4755,6 +4755,7 @@ static int LuaProgramMaxWorkers(lua_State *L) {
|
|||
}
|
||||
lua_pushinteger(L, maxworkers);
|
||||
if (lua_isinteger(L, 1)) maxworkers = lua_tointeger(L, 1);
|
||||
maxworkers = MAX(maxworkers, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -6749,6 +6750,12 @@ static int HandleConnection(size_t i) {
|
|||
if ((client = accept4(servers.p[i].fd, &clientaddr, &clientaddrsize,
|
||||
SOCK_CLOEXEC)) != -1) {
|
||||
startconnection = nowl();
|
||||
if (UNLIKELY(maxworkers) && shared->workers >= maxworkers) {
|
||||
EnterMeltdownMode();
|
||||
SendServiceUnavailable();
|
||||
close(client);
|
||||
return 0;
|
||||
}
|
||||
VERBOSEF("(srvr) accept %s via %s", DescribeClient(), DescribeServer());
|
||||
messageshandled = 0;
|
||||
if (hasonclientconnection && LuaOnClientConnection()) {
|
||||
|
@ -6939,7 +6946,6 @@ static int HandlePoll(int ms) {
|
|||
if (!polls[pollid].revents) continue;
|
||||
if (polls[pollid].fd < 0) continue;
|
||||
if (polls[pollid].fd) {
|
||||
if (maxworkers && shared->workers >= maxworkers) continue;
|
||||
// handle listen socket
|
||||
lua_repl_lock();
|
||||
serverid = pollid - 1;
|
||||
|
|
Loading…
Add table
Reference in a new issue