From 7c038112133f6ddcec46342c80b76cb5cb7bb14f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Sat, 16 Dec 2023 17:37:05 +0100 Subject: [PATCH 1/7] fix: random crash when starting or reloading --- frankenphp.c | 3 +++ test-reload.sh | 5 +++++ 2 files changed, 8 insertions(+) create mode 100644 test-reload.sh diff --git a/frankenphp.c b/frankenphp.c index 19da90d07f..d67997efd4 100644 --- a/frankenphp.c +++ b/frankenphp.c @@ -15,6 +15,7 @@ #include #include #include +#include #include "C-Thread-Pool/thpool.c" #include "C-Thread-Pool/thpool.h" @@ -667,6 +668,8 @@ static void *manager_thread(void *arg) { threadpool thpool = thpool_init(*((int *)arg)); free(arg); + sleep(1); + uintptr_t rh; while ((rh = go_fetch_request())) { diff --git a/test-reload.sh b/test-reload.sh new file mode 100644 index 0000000000..752098d2f1 --- /dev/null +++ b/test-reload.sh @@ -0,0 +1,5 @@ +#!/bin/bash +for ((i = 0 ; i < 100 ; i++)); do + curl http://localhost:2019/config/apps/frankenphp + curl -H 'Cache-Control: must-revalidate' --json '{"workers":[{"file_name":"./index.php"}]}' -X PATCH http://localhost:2019/config/apps/frankenphp +done From c1b16b3ec43237dcd66c0dece61058aff99fdf3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Sat, 16 Dec 2023 17:41:05 +0100 Subject: [PATCH 2/7] cs --- frankenphp.c | 3 +-- test-reload.sh | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/frankenphp.c b/frankenphp.c index d67997efd4..b00a708c64 100644 --- a/frankenphp.c +++ b/frankenphp.c @@ -668,8 +668,7 @@ static void *manager_thread(void *arg) { threadpool thpool = thpool_init(*((int *)arg)); free(arg); - sleep(1); - + sleep(1); /* FIXME: https://github.com/dunglas/frankenphp/pull/394 */ uintptr_t rh; while ((rh = go_fetch_request())) { diff --git a/test-reload.sh b/test-reload.sh index 752098d2f1..7892510e43 100644 --- a/test-reload.sh +++ b/test-reload.sh @@ -1,5 +1,5 @@ #!/bin/bash for ((i = 0 ; i < 100 ; i++)); do - curl http://localhost:2019/config/apps/frankenphp + curl http://localhost:2019/config/apps/frankenphp curl -H 'Cache-Control: must-revalidate' --json '{"workers":[{"file_name":"./index.php"}]}' -X PATCH http://localhost:2019/config/apps/frankenphp done From fe97d007691804173b0e68e5f82b5879ae60d686 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Sun, 17 Dec 2023 10:46:46 +0100 Subject: [PATCH 3/7] run tests --- .github/workflows/tests.yaml | 11 +++++++++++ test-reload.sh => reload_test.sh | 0 2 files changed, 11 insertions(+) rename test-reload.sh => reload_test.sh (100%) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index aed7375591..e7bb67de2d 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -53,6 +53,17 @@ jobs: name: Run Caddy module tests working-directory: caddy/ run: go test -race -v ./... + - + name: Build the server + working-directory: caddy/frankenphp/ + run: go build + - + name: Start the server + working-directory: testdata/ + run: sudo ../caddy/frankenphp/frankenphp start + - + name: Run integrations tests + run: ./reload_test.sh - name: Lint Go code uses: golangci/golangci-lint-action@v3 diff --git a/test-reload.sh b/reload_test.sh similarity index 100% rename from test-reload.sh rename to reload_test.sh From b5fe416b29b117534a036da208fc69fb8c196190 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Sun, 17 Dec 2023 11:26:02 +0100 Subject: [PATCH 4/7] fix perms --- reload_test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) mode change 100644 => 100755 reload_test.sh diff --git a/reload_test.sh b/reload_test.sh old mode 100644 new mode 100755 index 7892510e43..17427ef1cc --- a/reload_test.sh +++ b/reload_test.sh @@ -1,5 +1,5 @@ #!/bin/bash for ((i = 0 ; i < 100 ; i++)); do - curl http://localhost:2019/config/apps/frankenphp - curl -H 'Cache-Control: must-revalidate' --json '{"workers":[{"file_name":"./index.php"}]}' -X PATCH http://localhost:2019/config/apps/frankenphp + curl -sS -o /dev/null http://localhost:2019/config/apps/frankenphp + curl -sS -o /dev/null -H 'Cache-Control: must-revalidate' -H 'Content-Type: application/json' --data-binary '{"workers":[{"file_name":"./index.php"}]}' -X PATCH http://localhost:2019/config/apps/frankenphp done From 0c01296f6a02bf4309cb3cc890a0ff38f5414410 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Sun, 17 Dec 2023 11:49:12 +0100 Subject: [PATCH 5/7] better test --- reload_test.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/reload_test.sh b/reload_test.sh index 17427ef1cc..d35ff7a661 100755 --- a/reload_test.sh +++ b/reload_test.sh @@ -1,5 +1,4 @@ #!/bin/bash for ((i = 0 ; i < 100 ; i++)); do - curl -sS -o /dev/null http://localhost:2019/config/apps/frankenphp - curl -sS -o /dev/null -H 'Cache-Control: must-revalidate' -H 'Content-Type: application/json' --data-binary '{"workers":[{"file_name":"./index.php"}]}' -X PATCH http://localhost:2019/config/apps/frankenphp + curl --no-progress-meter -o /dev/null http://localhost:2019/config/apps/frankenphp -: --no-progress-meter -o /dev/null -H 'Cache-Control: must-revalidate' -H 'Content-Type: application/json' --data-binary '{"workers":[{"file_name":"./index.php"}]}' -X PATCH http://localhost:2019/config/apps/frankenphp done From 41fd0cf76dee01979f15be6f7a3d02a7aa429cc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Sun, 17 Dec 2023 14:45:29 +0100 Subject: [PATCH 6/7] wip --- frankenphp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frankenphp.c b/frankenphp.c index b00a708c64..284aeaf595 100644 --- a/frankenphp.c +++ b/frankenphp.c @@ -668,7 +668,7 @@ static void *manager_thread(void *arg) { threadpool thpool = thpool_init(*((int *)arg)); free(arg); - sleep(1); /* FIXME: https://github.com/dunglas/frankenphp/pull/394 */ + //sleep(1); /* FIXME: https://github.com/dunglas/frankenphp/pull/394 */ uintptr_t rh; while ((rh = go_fetch_request())) { From e09afeec0611361f3a72d2ac81a297520400f517 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Mon, 18 Dec 2023 01:16:19 +0100 Subject: [PATCH 7/7] better fix --- C-Thread-Pool/thpool.c | 2 ++ frankenphp.c | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/C-Thread-Pool/thpool.c b/C-Thread-Pool/thpool.c index 85a9381157..3ee8f6acb8 100644 --- a/C-Thread-Pool/thpool.c +++ b/C-Thread-Pool/thpool.c @@ -528,6 +528,8 @@ static void bsem_init(bsem *bsem_p, int value) { /* Reset semaphore to 0 */ static void bsem_reset(bsem *bsem_p) { + pthread_mutex_destroy(&(bsem_p->mutex)); + pthread_cond_destroy(&(bsem_p->cond)); bsem_init(bsem_p, 0); } diff --git a/frankenphp.c b/frankenphp.c index 284aeaf595..19f32c5f46 100644 --- a/frankenphp.c +++ b/frankenphp.c @@ -668,7 +668,6 @@ static void *manager_thread(void *arg) { threadpool thpool = thpool_init(*((int *)arg)); free(arg); - //sleep(1); /* FIXME: https://github.com/dunglas/frankenphp/pull/394 */ uintptr_t rh; while ((rh = go_fetch_request())) {