Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backports for 2.0.27 #2678

Merged
merged 14 commits into from
Sep 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,26 @@ jobs:
run: make unittests

test:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Install dependencies
run: |
sudo apt update -qq
sudo apt install --no-install-recommends -qqyf \
libpcre2-dev libjansson-dev libcap2-dev
libpcre2-dev libjansson-dev libcap2-dev \
php-dev libphp-embed libargon2-dev libsodium-dev \
pypy3
- uses: actions/checkout@v4
- name: Set env
run: echo "PROFILE=integration-tests" >> $GITHUB_ENV
- name: Run integration tests
run: make all tests

python:
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: ["2.7", "3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["2.7", "3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
test-suite: [python, deadlocks]
steps:
- name: Add deadnakes ppa
Expand Down
4 changes: 4 additions & 0 deletions buildconf/integration-tests.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[uwsgi]
inherit = base
main_plugin =
plugins = python,php,pypy
2 changes: 1 addition & 1 deletion core/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,8 @@ void sanitize_args() {
uwsgi.cores = uwsgi.async;
}

uwsgi.has_threads = 1;
if (uwsgi.threads > 1) {
uwsgi.has_threads = 1;
uwsgi.cores = uwsgi.threads;
}

Expand Down
1 change: 1 addition & 0 deletions core/loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ void *simple_loop_run(void *arg1) {
int main_queue = event_queue_init();

uwsgi_add_sockets_to_queue(main_queue, core_id);
event_queue_add_fd_read(main_queue, uwsgi.loop_stop_pipe[0]);

if (uwsgi.signal_socket > -1) {
event_queue_add_fd_read(main_queue, uwsgi.signal_socket);
Expand Down
6 changes: 6 additions & 0 deletions core/master_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ void uwsgi_destroy_processes() {

uwsgi_detach_daemons();

for (i = 1; i <= uwsgi.numproc; i++) {
if (uwsgi.workers[i].pid > 0) {
waitpid(uwsgi.workers[i].pid, &waitpid_status, 0);
}
}

for (i = 0; i < ushared->gateways_cnt; i++) {
if (ushared->gateways[i].pid > 0) {
kill(ushared->gateways[i].pid, SIGKILL);
Expand Down
32 changes: 24 additions & 8 deletions core/uwsgi.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ static struct uwsgi_option uwsgi_base_options[] = {
{"freebind", no_argument, 0, "put socket in freebind mode", uwsgi_opt_true, &uwsgi.freebind, 0},
#endif
{"map-socket", required_argument, 0, "map sockets to specific workers", uwsgi_opt_add_string_list, &uwsgi.map_socket, 0},
{"enable-threads", no_argument, 'T', "enable threads", uwsgi_opt_true, &uwsgi.has_threads, 0},
{"enable-threads", no_argument, 'T', "enable threads (stub option this is true by default)", uwsgi_opt_true, &uwsgi.has_threads, 0},
{"no-threads-wait", no_argument, 0, "do not wait for threads cancellation on quit/reload", uwsgi_opt_true, &uwsgi.no_threads_wait, 0},

{"auto-procname", no_argument, 0, "automatically set processes name to something meaningful", uwsgi_opt_true, &uwsgi.auto_procname, 0},
Expand Down Expand Up @@ -1224,16 +1224,17 @@ void gracefully_kill(int signum) {

uwsgi_log("Gracefully killing worker %d (pid: %d)...\n", uwsgi.mywid, uwsgi.mypid);
uwsgi.workers[uwsgi.mywid].manage_next_request = 0;

if (uwsgi.threads > 1) {
struct wsgi_request *wsgi_req = current_wsgi_req();
wait_for_threads();
if (!uwsgi.workers[uwsgi.mywid].cores[wsgi_req->async_id].in_request) {
if (uwsgi.workers[uwsgi.mywid].shutdown_sockets)
uwsgi_shutdown_all_sockets();
exit(UWSGI_RELOAD_CODE);
// Stop event_queue_wait() in other threads.
// We use loop_stop_pipe only in threaded workers to avoid
// unintensional behavior changes in single threaded workers.
int fd;
if ((fd = uwsgi.loop_stop_pipe[1]) > 0) {
close(fd);
uwsgi.loop_stop_pipe[1] = 0;
}
return;
// never here
}

// still not found a way to gracefully reload in async mode
Expand Down Expand Up @@ -1265,6 +1266,17 @@ static void simple_goodbye_cruel_world() {
// Avoid showing same message from all threads.
uwsgi_log("...The work of process %d is done. Seeya!\n", getpid());
}

if (uwsgi.threads > 1) {
// Stop event_queue_wait() in other threads.
// We use loop_stop_pipe only in threaded workers to avoid
// unintensional behavior changes in single threaded workers.
int fd;
if ((fd = uwsgi.loop_stop_pipe[1]) > 0) {
close(fd);
uwsgi.loop_stop_pipe[1] = 0;
}
}
}

void goodbye_cruel_world() {
Expand Down Expand Up @@ -3539,6 +3551,10 @@ void uwsgi_ignition() {
exit(1);
}
}
if (pipe(&uwsgi.loop_stop_pipe[0])) {
uwsgi_error("pipe()")
exit(1);
}

// mark the worker as "accepting" (this is a mark used by chain reloading)
uwsgi.workers[uwsgi.mywid].accepting = 1;
Expand Down
2 changes: 2 additions & 0 deletions plugins/php/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@

#include "ext/session/php_session.h"

#include "ext/standard/head.h"

#include <uwsgi.h>

16 changes: 16 additions & 0 deletions plugins/php/php_plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,21 @@ PHP_FUNCTION(uwsgi_signal) {
RETURN_NULL();
}

PHP_FUNCTION(uwsgi_disconnect) {

struct wsgi_request *wsgi_req = (struct wsgi_request *) SG(server_context);

php_output_end_all();
php_header();

uwsgi_disconnect(wsgi_req);

php_output_set_status(PHP_OUTPUT_DISABLED);

RETURN_NULL();
}


ZEND_BEGIN_ARG_INFO_EX(arginfo_void, 0, 0, 0)
ZEND_END_ARG_INFO()

Expand All @@ -507,6 +522,7 @@ zend_function_entry uwsgi_php_functions[] = {
PHP_FE(uwsgi_cache_del, arginfo_void)
PHP_FE(uwsgi_cache_clear, arginfo_void)
PHP_FE(uwsgi_cache_exists, arginfo_void)
PHP_FE(uwsgi_disconnect, arginfo_void)
{ NULL, NULL, NULL},
};

Expand Down
Loading