Skip to content

Commit 6519cb4

Browse files
committed
re-enable rctx:sleep
looks like the IO refactor fixes it!
1 parent 361905b commit 6519cb4

File tree

3 files changed

+1
-28
lines changed

3 files changed

+1
-28
lines changed

proxy_lua.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1659,7 +1659,7 @@ int proxy_register_libs(void *ctx, LIBEVENT_THREAD *t, void *state) {
16591659
{"tls_peer_cn", mcplib_rcontext_tls_peer_cn},
16601660
{"request_new", mcplib_rcontext_request_new},
16611661
{"response_new", mcplib_rcontext_response_new},
1662-
//{"sleep", mcplib_rcontext_sleep}, see comments on function
1662+
{"sleep", mcplib_rcontext_sleep},
16631663
{NULL, NULL}
16641664
};
16651665

proxy_luafgen.c

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,32 +1328,6 @@ int mcplib_rcontext_wait_handle(lua_State *L) {
13281328
return lua_yield(L, 1);
13291329
}
13301330

1331-
// TODO: This is disabled due to issues with the IO subsystem. Fixing this
1332-
// requires retiring of API1 to allow refactoring or some extra roundtrip
1333-
// work.
1334-
// - if rctx:sleep() is called, the coroutine is suspended.
1335-
// - once resumed after the timeout, we may later suspend again and make
1336-
// backend requests
1337-
// - once the coroutine is completed, we need to check if the owning client
1338-
// conn is ready to be resumed
1339-
// - BUG: we can only get into the "conn is in IO queue wait" state if a
1340-
// sub-IO was created and submitted somewhere.
1341-
// - This means either rctx:sleep() needs to be implemented by submitting a
1342-
// dummy IO req (as other code does)
1343-
// - OR we need to refactor the IO system so the dummies aren't required
1344-
// anymore.
1345-
//
1346-
// If a dummy is used, we would have to implement this as:
1347-
// - immediately submit a dummy IO if sleep is called.
1348-
// - this allows the IO system to move the connection into the right state
1349-
// - will immediately circle back then set an alarm for the sleep timeout
1350-
// - once the sleep resumes, run code as normal. resumption should work
1351-
// properly since we've entered the correct state originally.
1352-
//
1353-
// This adds a lot of CPU overhead to sleep, which should be fine given the
1354-
// nature of the function, but also adds a lot of code and increases the
1355-
// chances of bugs. So I'm leaving it out until this can be implemented more
1356-
// simply.
13571331
int mcplib_rcontext_sleep(lua_State *L) {
13581332
mcp_rcontext_t *rctx = lua_touserdata(L, 1);
13591333
if (rctx->wait_mode != QWAIT_IDLE) {

t/proxyrctxtimeout.t

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ $t->set_c($ps);
2828
$t->accept_backends();
2929

3030
subtest 'sleep' => sub {
31-
plan skip_all => 'sleep does not work';
3231
$t->c_send("mg sleep/foo t\r\n");
3332
$t->be_recv_c(0, "near got request");
3433
$t->be_send(0, "HD t94\r\n");

0 commit comments

Comments
 (0)