Skip to content

Commit fb1e739

Browse files
committed
fix: http and playground test bug
1 parent 4b9522d commit fb1e739

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

runtime/nutils/http.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "http.h"
2-
#include "runtime/runtime.h"
32
#include "runtime/processor.h"
43
#include "runtime/rt_mutex.h"
4+
#include "runtime/runtime.h"
55

66
#define DEFAULT_BACKLOG 128
77

@@ -22,10 +22,16 @@ static inline void on_async_close_cb(uv_handle_t *handle) {
2222

2323
static inline void on_close_cb(uv_handle_t *handle) {
2424
conn_ctx_t *ctx = CONTAINER_OF(handle, conn_ctx_t, client_handle);
25-
DEBUGF("[on_close_cb] ctx, %p, client_handle: %p", ctx, &ctx->client_handle);
25+
DEBUGF("[on_close_cb] ctx, %p, client_handle: %p, async_handle: %p",
26+
ctx, &ctx->client_handle, ctx->async_handle);
27+
2628

27-
// 需要先关闭 async 才能释放内存 TODO 检查 async_handle 是否创建
28-
uv_close((uv_handle_t *) &ctx->async_handle, on_async_close_cb);
29+
// 需要先关闭 async 才能释放内存
30+
if (uv_is_active((uv_handle_t *) &ctx->async_handle)) {
31+
uv_close((uv_handle_t *) &ctx->async_handle, on_async_close_cb);
32+
} else {
33+
DEBUGF("[on_close_cb] ctx async_handle not active, not need close")
34+
}
2935

3036
// free(ctx->read_buf_base);
3137
// free(ctx->write_buf.base);

tests/features/20250418_00_playground.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ char *code5 = "fn main() {\n"
8989

9090
int main(void) {
9191
feature_test_build();
92-
// exec_imm_param();
9392

9493
pid_t pid = fork();
9594
if (pid == 0) {
@@ -106,8 +105,8 @@ int main(void) {
106105

107106
for (int i = 0; i < 20; ++i) {
108107
snprintf(curl_cmd, sizeof(curl_cmd),
109-
"curl -s -X POST http://127.0.0.1:8888/api/playgrounds/run"
110-
"-H 'content-type: text/plain' --data-binary '%s'",
108+
"curl -s -X POST http://127.0.0.1:8888/playgrounds/run"
109+
" -H 'content-type: text/plain' --data-binary '%s'",
111110
code1);
112111
FILE *fp = popen(curl_cmd, "r");
113112
fread(buf, 1, sizeof(buf) - 1, fp);

0 commit comments

Comments
 (0)