Skip to content

Commit

Permalink
add session_lock_failing test
Browse files Browse the repository at this point in the history
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:

  websupport-sk#4  0x00007fc675426c46 in __assert_fail () from /lib64/libc.so.6
  websupport-sk#5  0x00007fc670cbcaf3 in zend_gc_delref (p=0x7fc670bbc000) at /opt/php/include/php/Zend/zend_types.h:1209
  websupport-sk#6  0x00007fc670cbcb59 in zval_delref_p (pz=0x7ffe587973a0) at /opt/php/include/php/Zend/zend_types.h:1245
  websupport-sk#7  0x00007fc670cbcc81 in zval_ptr_dtor_nogc (zval_ptr=0x7ffe587973a0) at /opt/php/include/php/Zend/zend_variables.h:34
  websupport-sk#8  0x00007fc670cbdcbc in ps_read_memcache (mod_data=0x7fc674bed980 <ps_globals+96>, key=0x7fc670b81540, val=0x7ffe58797428,
      maxlifetime=3600) at /srv/dev/yin/phb/build/ourphp-8.1.15-debug/memcache/src/memcache_session.c:385
  websupport-sk#9  0x00007fc673cd7ab3 in php_session_initialize ()
      at /srv/dev/yin/phb/build/ourphp-8.1.15-debug/php-src/ext/session/session.c:444
  websupport-sk#10 0x00007fc673cdafa3 in php_session_start () at /srv/dev/yin/phb/build/ourphp-8.1.15-debug/php-src/ext/session/session.c:1612
  websupport-sk#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
  websupport-sk#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
  websupport-sk#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
  websupport-sk#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
  websupport-sk#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)
  • Loading branch information
bof committed Feb 5, 2023
1 parent 26c0f51 commit b87d742
Showing 1 changed file with 89 additions and 0 deletions.
89 changes: 89 additions & 0 deletions tests/session_lock_failing.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
--TEST--
failed session locking test
--SKIPIF--
<?php include 'connect.inc'; if (!MEMCACHE_HAVE_SESSION) print 'skip not compiled with session support'; else if (!function_exists('pcntl_fork')) print 'skip not compiled with pcntl_fork() support'; ?>
--FILE--
<?php

ob_start();

include 'connect.inc';

# purpose of this test is to check that ps_read_session() does the right thing
# in case it cannot lock the session.
#
# strategy is to open a session, then fork a child to do the actual testing.

ini_set('session.use_strict_mode', 0);
ini_set('memcache.session_redundancy', 2);
ini_set('session.save_handler', 'memcache');
ini_set('memcache.session_save_path', "tcp://$host:$port?udp_port=$udpPort, tcp://$host2:$port2?udp_port=$udpPort2");
ini_set('memcache.lock_timeout', 1); # actual value is doubled in ps_read_session() --> 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

0 comments on commit b87d742

Please sign in to comment.