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