ext-openswoole
ext-openswoole copied to clipboard
Swoole\Table::[someMethod]() table is not created or has been destroyed
- What did you do? If possible, provide a simple script for reproducing the error.
Use Swoole\Table in a connection tracking object property.
- What did you expect to see?
Swoole table should not go away
- What did you see instead?
**MOST** time it does work. But from time to time I see the following error:
PHP Fatal error: Swoole\Table::get(): table is not created or has been destroyed in /var/www/apps/frontend/websocket/WsConnections.php on line 164
Symfony\Component\ErrorHandler\Error\FatalError^ {#117
#message: "Error: Swoole\Table::get(): table is not created or has been destroyed"
#code: 0
#file: "/var/www/apps/frontend/websocket/WsConnections.php"
#line: 164
-error: array:4 [
"type" => 1
"message" => "Swoole\Table::get(): table is not created or has been destroyed"
"file" => "/var/www/apps/frontend/websocket/WsConnections.php"
"line" => 164
]
}
or
PHP Fatal error: Swoole\Table::rewind(): table is not created or has been destroyed in /var/www/apps/frontend/websocket/WsConnections.php on line 404
- What version of OpenSwoole are you using (show your
php --ri openswoole
)?
openswoole
Open Swoole => enabled
Author => Open Swoole Group <[email protected]>
Version => 4.11.1
Built => Sep 21 2022 11:26:35
coroutine => enabled with boost asm context
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
openssl => OpenSSL 1.1.1n 15 Mar 2022
dtls => enabled
zlib => 1.2.11
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
async_redis => enabled
Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => On => On
swoole.unixsock_buffer_size => 8388608 => 8388608
- What is your machine environment used (show your
uname -a
&php -v
&gcc -v
) ?
Linux dev01 5.10.0-18-amd64 #1 SMP Debian 5.10.140-1 (2022-09-02) x86_64 GNU/Linux
PHP 8.1.10 (cli) (built: Sep 18 2022 12:52:19) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.10, Copyright (c) Zend Technologies
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/10/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 10.2.1-6' --with-bugurl=file:///usr/share/doc/gcc-10/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-10 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-10-Km9U7s/gcc-10-10.2.1/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-10-Km9U7s/gcc-10-10.2.1/debian/tmp-gcn/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-mutex
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.2.1 20210110 (Debian 10.2.1-6)
It could be caused by lifecycle management of table, so please provide minimum code to reproduce the issue.
That error happens randomly. Haven't seen it since yesterday and I have absolutely no idea how to reproduce it reliably.
I use swoole/table for connection<->member login tracking on an object property. So I'm passing that object almost everywhere in my application which is websocket context:
- server->onStart for initialization
- server->onOpen when member connects
- server->onMessage when members do actions in chat
- server->onClose when members log out
//constructor
$this->connections = new Table(self::MAX_CONNECTIONS_UNAPPROVED);
$this->connections->column('fd', Table::TYPE_INT);
$this->connections->column('state', Table::TYPE_STRING, 16);
$this->connections->column('member_id', Table::TYPE_INT);
$this->connections->column('user_json', Table::TYPE_STRING, 2048);
$this->connections->create();
$this->loggedInMembers = new Table(self::MAX_LOGGED_IN_MEMBERS);
$this->loggedInMembers->column('member_id', Table::TYPE_INT);
$this->loggedInMembers->column('connections', Table::TYPE_STRING, 128);
$this->loggedInMembers->create();
At one place I need to search the table, I'm not sure if this may be causing some trouble:
for ($this->loggedInMembers->rewind(); $this->loggedInMembers->valid(); $this->loggedInMembers->next()) {
//only calling $this->loggedInMembers->current() in here
}
Any advice/hint appreciated. I will report back when I have new information.