From 52576a2b9991615cc604a2e3057b0ea014ecd301 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Mon, 27 Jan 2025 23:14:33 +0100 Subject: [PATCH 1/4] ci: use Alpine 3.21 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4ea05d4a..6cbe3073 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -121,7 +121,7 @@ jobs: build-alpine: name: Alpine Linux runs-on: ubuntu-latest - container: alpine:3.19 + container: alpine:3.21 strategy: fail-fast: false matrix: From 8acb06e495c8fd1d2e112da9108c202c904e0da2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Mon, 27 Jan 2025 23:26:33 +0100 Subject: [PATCH 2/4] ci: use system ffi on Alpine --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6cbe3073..9270b56e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -130,7 +130,7 @@ jobs: BUILDTYPE: ${{ matrix.buildType }} steps: - name: Prepare - run: apk add git build-base cmake curl-dev autoconf automake libtool texinfo linux-headers --update-cache + run: apk add git build-base cmake curl-dev autoconf automake libtool texinfo linux-headers libffi-dev --update-cache - uses: actions/checkout@v4 with: submodules: true @@ -138,7 +138,7 @@ jobs: with: node-version-file: '.nvmrc' - name: Build it - run: make VERBOSE=1 + run: make VERBOSE=1 USE_EXTERNAL_FFI=ON - name: Test it run: make test build-windows: From 1e22d5fa350857f7e9521552a9c717440350a061 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Mon, 27 Jan 2025 23:35:06 +0100 Subject: [PATCH 3/4] curl: handle socket failures more gracefully --- src/curl-utils.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/curl-utils.c b/src/curl-utils.c index f4bf8fe6..ac5b9f87 100644 --- a/src/curl-utils.c +++ b/src/curl-utils.c @@ -165,11 +165,15 @@ static void uv__poll_cb(uv_poll_t *handle, int status, int events) { CHECK_NOT_NULL(qrt); int flags = 0; - if (events & UV_READABLE) { - flags |= CURL_CSELECT_IN; - } - if (events & UV_WRITABLE) { - flags |= CURL_CSELECT_OUT; + if (status != 0) { + flags |= CURL_CSELECT_ERR; + } else { + if (events & UV_READABLE) { + flags |= CURL_CSELECT_IN; + } + if (events & UV_WRITABLE) { + flags |= CURL_CSELECT_OUT; + } } int running_handles; @@ -197,12 +201,11 @@ static int curl__handle_socket(CURL *easy, curl_socket_t s, int action, void *us poll_ctx->qrt = qrt; poll_ctx->sockfd = s; poll_ctx->poll.data = poll_ctx; + curl_multi_assign(qrt->curl_ctx.curlm_h, s, (void *) poll_ctx); } else { poll_ctx = socketp; } - curl_multi_assign(qrt->curl_ctx.curlm_h, s, (void *) poll_ctx); - int events = 0; if (action != CURL_POLL_IN) { events |= UV_WRITABLE; @@ -222,8 +225,8 @@ static int curl__handle_socket(CURL *easy, curl_socket_t s, int action, void *us uv_close((uv_handle_t *) &poll_ctx->poll, uv__poll_close_cb); } break; - default: - abort(); + case CURL_POLL_NONE: + break; } return 0; From b6f48a88ba3672a696f44ff6969a77558b981a57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Tue, 28 Jan 2025 10:13:10 +0100 Subject: [PATCH 4/4] vm: destroy curl handle before destroying the loop In case any final callbacks are fired. --- src/vm.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/vm.c b/src/vm.c index 4e27c170..151347f8 100644 --- a/src/vm.c +++ b/src/vm.c @@ -350,6 +350,16 @@ void TJS_FreeRuntime(TJSRuntime *qrt) { JS_FreeContext(qrt->ctx); JS_FreeRuntime(qrt->rt); + /* Destroy CURLM handle. */ + if (qrt->curl_ctx.curlm_h) { + curl_multi_cleanup(qrt->curl_ctx.curlm_h); + qrt->curl_ctx.curlm_h = NULL; + } + + /* Destroy WASM runtime. */ + m3_FreeEnvironment(qrt->wasm_ctx.env); + qrt->wasm_ctx.env = NULL; + /* Cleanup loop. All handles should be closed. */ int closed = 0; for (int i = 0; i < 5; i++) { @@ -368,16 +378,6 @@ void TJS_FreeRuntime(TJSRuntime *qrt) { (void) closed; #endif - /* Destroy CURLM handle. */ - if (qrt->curl_ctx.curlm_h) { - curl_multi_cleanup(qrt->curl_ctx.curlm_h); - qrt->curl_ctx.curlm_h = NULL; - } - - /* Destroy WASM runtime. */ - m3_FreeEnvironment(qrt->wasm_ctx.env); - qrt->wasm_ctx.env = NULL; - tjs__free(qrt); }