From b87d742ab472d67ca3282960c1bb2d72ab3358b8 Mon Sep 17 00:00:00 2001 From: Patrick Schaaf Date: Sun, 5 Feb 2023 18:06:59 +0100 Subject: [PATCH] add session_lock_failing test In an attempt to provoke the debug build assertion failure I saw, this is the first attempt at a test case provoking it. Doesn't work, yet... Context on the assertion failure: #4 0x00007fc675426c46 in __assert_fail () from /lib64/libc.so.6 #5 0x00007fc670cbcaf3 in zend_gc_delref (p=0x7fc670bbc000) at /opt/php/include/php/Zend/zend_types.h:1209 #6 0x00007fc670cbcb59 in zval_delref_p (pz=0x7ffe587973a0) at /opt/php/include/php/Zend/zend_types.h:1245 #7 0x00007fc670cbcc81 in zval_ptr_dtor_nogc (zval_ptr=0x7ffe587973a0) at /opt/php/include/php/Zend/zend_variables.h:34 #8 0x00007fc670cbdcbc in ps_read_memcache (mod_data=0x7fc674bed980 , key=0x7fc670b81540, val=0x7ffe58797428, maxlifetime=3600) at /srv/dev/yin/phb/build/ourphp-8.1.15-debug/memcache/src/memcache_session.c:385 #9 0x00007fc673cd7ab3 in php_session_initialize () at /srv/dev/yin/phb/build/ourphp-8.1.15-debug/php-src/ext/session/session.c:444 #10 0x00007fc673cdafa3 in php_session_start () at /srv/dev/yin/phb/build/ourphp-8.1.15-debug/php-src/ext/session/session.c:1612 #11 0x00007fc673cded07 in zif_session_start (execute_data=0x7fc670a12d30, return_value=0x7fc670a12d10) at /srv/dev/yin/phb/build/ourphp-8.1.15-debug/php-src/ext/session/session.c:2533 #12 0x00007fc673feea58 in ZEND_DO_ICALL_SPEC_RETVAL_USED_HANDLER () at /srv/dev/yin/phb/build/ourphp-8.1.15-debug/php-src/Zend/zend_vm_execute.h:1297 #13 0x00007fc674063f3c in execute_ex (ex=0x7fc670a12930) at /srv/dev/yin/phb/build/ourphp-8.1.15-debug/php-src/Zend/zend_vm_execute.h:55779 #14 0x00007fc673f9a4c3 in zend_call_function (fci=0x7ffe58797990, fci_cache=0x7ffe58797970) at /srv/dev/yin/phb/build/ourphp-8.1.15-debug/php-src/Zend/zend_execute_API.c:912 #15 0x00007fc673f9a97d in zend_call_known_function (fn=0x7fc610866500, object=0x0, called_scope=0x0, retval_ptr=0x0, param_count=1, params=0x7ffe58797a20, named_params=0x0) --- tests/session_lock_failing.phpt | 89 +++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 tests/session_lock_failing.phpt diff --git a/tests/session_lock_failing.phpt b/tests/session_lock_failing.phpt new file mode 100644 index 0000000..8b1ca56 --- /dev/null +++ b/tests/session_lock_failing.phpt @@ -0,0 +1,89 @@ +--TEST-- +failed session locking test +--SKIPIF-- + +--FILE-- + 2 seconds + +# make sure no shit is leftover from previous test +$key = 'memcache_tests_session_lock'; +$keylock = 'memcache_tests_session_lock.lock'; +$mc = test_connect1(); $mc->delete($key); $mc->delete($keylock); +$mc = test_connect2(); $mc->delete($key); $mc->delete($keylock); + +function microtime_float() +{ + list($usec, $sec) = explode(" ", microtime()); + return ((float)$usec + (float)$sec); +} + +function session_str() +{ + return strtr(var_export($_SESSION, true), "\n", " "); +} + +$t1 = microtime_float(); + +$t2 = microtime_float(); +printf("[%.06f] parent BEGIN\n", $t2 - $t1); +session_id($key); +session_start(); +$_SESSION['test']=true; +$t2 = microtime_float(); +printf("[%.06f] parent %s\n", $t2 - $t1, session_str()); +session_write_close(); + +$pid = pcntl_fork(); +if (!$pid) { + ob_clean(); + ob_start(); + printf("[%.06f] child BEGIN\n", $t2 - $t1); + usleep(250000); + session_id($key); + session_start(); + $t2 = microtime_float(); + printf("[%.06f] child %s\n", $t2 - $t1, session_str()); + session_write_close(); + $t2 = microtime_float(); + printf("[%.06f] child EXIT\n", $t2 - $t1); + ob_flush(); + exit(0); +} + +session_id($key); +session_start(); +$t2 = microtime_float(); +printf("[%.06f] parent %s\n", $t2 - $t1, session_str()); +usleep(4000000); +$t2 = microtime_float(); +printf("[%.06f] parent RESUME\n", $t2 - $t1); +session_write_close(); +$t2 = microtime_float(); +printf("[%.06f] parent EXIT\n", $t2 - $t1); + +ob_flush(); + +?> +--EXPECTF-- +[0.%f] child BEGIN +[0.%f] child array ( ) +[0.%f] child EXIT +[0.%f] parent BEGIN +[0.%f] parent array ( ) +[4.%f] parent RESUME +[4.%f] parent EXIT