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

Access to undeclared static property #1530

Closed
xqkeji opened this issue May 2, 2017 · 55 comments
Closed

Access to undeclared static property #1530

xqkeji opened this issue May 2, 2017 · 55 comments
Labels

Comments

@xqkeji
Copy link

xqkeji commented May 2, 2017

When ajax request more than 3 times, there will be "Access to undeclared static property"
E.g

namespace XqKeji;

class Di
{
	private static _default;

	public static function getInstance()
	{
		var di
		let di = self::_default;

		if !di {
			let di = new self();
			let self::_default = di;
		}

		return self::_default;
	}
}
class app
{
	public function __construct()
	{
		var di;
		let di = \XqKeji\Di::getInstance();
	}
}

Test:

<?php
$App = new App();

in window php7.0 ts

@xqkeji
Copy link
Author

xqkeji commented May 2, 2017

zephir_read_static_property_ce(&di, xqkeji_di_ce, SL("_default"), PH_NOISY_CC);

Does php7 do not need TSRMLS_CC

@xqkeji xqkeji changed the title Access to undeclared static propert Access to undeclared static property May 2, 2017
@xqkeji
Copy link
Author

xqkeji commented May 2, 2017

As long as the load is high, will appear "Access to undeclared static property"。

@Jurigag
Copy link
Contributor

Jurigag commented May 2, 2017

Add that this happens only on php apache module, on cli or fpm it works fine and without issues.

@sergeyklay sergeyklay added the bug label May 2, 2017
@sergeyklay
Copy link
Contributor

@sjinks Could you please take a look

@hakimio
Copy link

hakimio commented May 19, 2017

@sjinks It's rather important that you take a look at this bug as soon as possible, because it prevents usage of thread-safe extension on any platform, not only windows. So, it's no longer possible to use phalcon with pthreads and similar stuff which actually requires thread safety.

@sergeyklay sergeyklay added this to the 2017-Q2 milestone May 19, 2017
@afbora
Copy link

afbora commented Jul 28, 2017

I got this error on Phalcon 3.2.0 today.
Its gone when i refresh the page 😕

@sergeyklay sergeyklay self-assigned this Oct 27, 2017
@sergeyklay
Copy link
Contributor

sergeyklay commented Oct 28, 2017

@php318 Could you change your code to:

namespace XqKeji;

class Di
{
	private static _default;

	public static function getInstance()
	{
-		var di
-		let di = self::_default;

-		if !di {
+		if typeof self::_default !== "object" {
-			let di = new self();
-			let self::_default = di;
+			let self::_default = new self();
		}

		return self::_default;
	}
}

and test it

@sergeyklay
Copy link
Contributor

/ cc: @hakimio, @afbora

@Jurigag
Copy link
Contributor

Jurigag commented Oct 28, 2017

@sergeyklay i saw you are doing some tests with this, are you sure you are doing it on TS php? Beacause as i remember this is main issue, but not sure.

sergeyklay added a commit that referenced this issue Oct 29, 2017
@xqkeji
Copy link
Author

xqkeji commented Nov 19, 2017

@sergeyklay
I test it, the error still exists.

@mattysj66
Copy link

mattysj66 commented Jan 16, 2018

Hey guys, what was the outcome to this bug?

I'm encountering the same issue on Windows and Apache 2.4 running PHP 7.1.1 and Phalcon 3.2.4

@hakimio
Copy link

hakimio commented Jan 16, 2018

@mattratcliffe86 Use nginx + php-fpm instead of Apache. There are some issues with thread safety of the extension.
https://www.progressivethink.in/on/administration/and/setup-nginx-and-php-on-windows/
https://docs.phalconphp.com/en/latest/webserver-setup#nginx

@mattysj66
Copy link

@hakimio Thanks for that.

So this is specifically affecting the thread safe extension for Apache, just on Windows or is it Linux too?

@hakimio
Copy link

hakimio commented Jan 16, 2018

@mattratcliffe86 It's effecting both windows and linux thread-safe extensions.

@Pilsenerek
Copy link

I have the same problem:
Phalcon 3.3.1
System Win7
PHP:

  • version 7.2
  • tread safe enabled
  • architecture x86
  • compiler MSVC15

It occurs especially when there are many requests in the same time or fast one by one in row.

@hakimio
Copy link

hakimio commented Feb 4, 2018

@Pilsenerek
Its's an old well-known issue. See the following: phalcon/cphalcon#12056

@sergeyklay
Copy link
Contributor

I'm going to solve this issue so I need code to reproduce guys. Could someone provide a worked (badly) example?

@hakimio
Copy link

hakimio commented Feb 27, 2018

@sergeyklay It's rather easy to reproduce the issue. You just need to run phalcon Thread-Safe extension with Apache on Windows (some people reported the issue on Linux as well but I've never tried running Phalcon TS on Linux personally) and then just make a large number of parallel requests (shouldn't need more than a 100) to a single end-point which does some simulated work ("usleep(100000)" should work just fine).

@sergeyklay
Copy link
Contributor

sergeyklay commented Mar 1, 2018

I need to locate problem. So it is too complex to use full framework to debug this. Actually I need an example as small as possible

@hakimio
Copy link

hakimio commented Mar 1, 2018

Maybe then create a simple Zephir extension, compile it with TS and use pthreads to check if it is actually thread safe?

@mattysj66
Copy link

mattysj66 commented Mar 1, 2018

@sergeyklay

Quick and dirty way to reproduce the error...
ptest.zip

I've created a controller 'reload' which just reloads the page a given number of times and increments the value in the url segment by 1 each time. I'm redirecting, which is what I did when I first encountered the problem. Same thing occurs when you use $response->redirect() (\Phalcon\Http\Response) or the native header() function in PHP.

PHP Fatal error: Uncaught Error: Access to undeclared static property Phalcon\Di::$_default in index.php on line 10

Line 10 happens to be $di = new FactoryDefault();

@sergeyklay sergeyklay removed this from the 2017-Q2 milestone Apr 9, 2018
@stijn1989
Copy link

I still have this error (Phalcon 3.3.2 with PHP7.2) when the app performs two ajax requests at the same time. If I perform the first ajax call and 500ms later I call the second ajax, it works.

@dreamsxin
Copy link
Contributor

dreamsxin commented Feb 19, 2019

I can't reproduce,

Ubuntu 16.04
Zephir 0.11.10
PHP 7.2.15 (cli) (built: Feb 19 2019 16:14:30) ( ZTS DEBUG )
Phalcon v4.0.0-alpha.2

ab -c 20 -n 200 http://localhost:8181/

Another test code:

namespace Mytest;

class Di
{
	private static _default;

	public static function getInstance()
	{
		var di;
		let di = self::_default;

		if !di {
			let di = new self();
			let self::_default = di;
		}

		return self::_default;
	}
}

class App
{
	public function __construct()
	{
		var di;
		let di = Di::getInstance();
	}
}

Phalcon v3.4.0

PHP Fatal error:  Declaration of Phalcon\Forms\Element::getAttribute(string $attribute, $defaultValue = NULL) must be compatible with Phalcon\Forms\ElementInterface::getAttribute($attribute, $defaultValue = NULL) in Unknown on line 0
...

@sergeyklay
Copy link
Contributor

sergeyklay commented Feb 19, 2019

@dreamsxin You have to use Zephir 0.10.x for Phalcon 3.x and Zephir 0.11.x for Phalcon 4.x. This is why you get "PHP Fatal error" for Phalcon v3.4.0 using Zephir 0.11.x

Did you use Thread-Safe extension with Apache ? It is important here

@dreamsxin
Copy link
Contributor

@sergeyklay I don't have an apache environment.

@sergeyklay
Copy link
Contributor

@dreamsxin Is there any chance that you will be able to use a Docker or any VM?

@dreamsxin
Copy link
Contributor

@sergeyklay I'm not sure that under Linux, libapache-mod-php uses thread safe, and my computer is too old. It would be great if you can test and get core dump.

@hakimio
Copy link

hakimio commented Feb 21, 2019

@dreamsxin you should be able to reproduce the issue with TS php-cli as well.

@dreamsxin
Copy link
Contributor

@hakimio Can't reproduce, Previously tested in CLI

Ubuntu 16.04
Zephir 0.11.10
PHP 7.2.15 (cli) (built: Feb 19 2019 16:14:30) ( ZTS DEBUG )
Phalcon v4.0.0-alpha.2

@CameronHall
Copy link

CameronHall commented Feb 26, 2019

@dreamsxin I managed to produce a dump. That's a pretty version produced by DebugDiag Analysis 2 that you'll need to open with a browser.

If you need the .dmp let me know on Discord.

@dreamsxin
Copy link
Contributor

I will feedback

@dreamsxin
Copy link
Contributor

@CameronHall Unfortunately, my computer is not Windows.
And the use of virtual machines (xp systems), as shown below

DebugDiag Analysis cannot be performed against a 64-bit dump file from a 32-bit analysis machine. Please run the analysis on a 64-bit machine to get analysis details.

I want to admire that the document is too big.

@CameronHall
Copy link

No worries. If you're okay with the HTML files from DebugDiag, I can generate them for the other dumps I send to you via email.

@CameronHall
Copy link

I sent @dreamsxin the dumps. I also sent him this stack trace.

KERNELBASE!wil::details::DebugBreak+2	  
php7ts_debug!zend_output_debug_string+a1 [c:\php-sdk\phpmaster\vc15\x64\php-src\zend\zend.c @ 1445]	  c:\php-sdk\phpmaster\vc15\x64\php-src\zend\zend.c @ 1445
php7ts_debug!php_error_cb+1027 [c:\php-sdk\phpmaster\vc15\x64\php-src\main\main.c @ 1218]	  c:\php-sdk\phpmaster\vc15\x64\php-src\main\main.c @ 1218
php7ts_debug!soap_error_handler+21c [c:\php-sdk\phpmaster\vc15\x64\php-src\ext\soap\soap.c @ 2129 + 3c]	  c:\php-sdk\phpmaster\vc15\x64\php-src\ext\soap\soap.c @ 2129 + 3c
php7ts_debug!zend_error_va_list+57c [c:\php-sdk\phpmaster\vc15\x64\php-src\zend\zend.c @ 1221 + 32]	  c:\php-sdk\phpmaster\vc15\x64\php-src\zend\zend.c @ 1221 + 32
php7ts_debug!zend_error_noreturn+48 [c:\php-sdk\phpmaster\vc15\x64\php-src\zend\zend.c @ 1343]	  c:\php-sdk\phpmaster\vc15\x64\php-src\zend\zend.c @ 1343
php7ts_debug!zend_timeout+bd [c:\php-sdk\phpmaster\vc15\x64\php-src\zend\zend_execute_api.c @ 1162]	  c:\php-sdk\phpmaster\vc15\x64\php-src\zend\zend_execute_api.c @ 1162
php7ts_debug!zend_interrupt_helper_SPEC+97 [c:\php-sdk\phpmaster\vc15\x64\php-src\zend\zend_vm_execute.h @ 2076 + 7]	  c:\php-sdk\phpmaster\vc15\x64\php-src\zend\zend_vm_execute.h @ 2076 + 7
php7ts_debug!ZEND_DO_ICALL_SPEC_RETVAL_UNUSED_HANDLER+2b4 [c:\php-sdk\phpmaster\vc15\x64\php-src\zend\zend_vm_execute.h @ 596 + 5c]	  c:\php-sdk\phpmaster\vc15\x64\php-src\zend\zend_vm_execute.h @ 596 + 5c
php7ts_debug!execute_ex+8d [c:\php-sdk\phpmaster\vc15\x64\php-src\zend\zend_vm_execute.h @ 59739 + f]	  c:\php-sdk\phpmaster\vc15\x64\php-src\zend\zend_vm_execute.h @ 59739 + f
php7ts_debug!zend_call_function+f1c [c:\php-sdk\phpmaster\vc15\x64\php-src\zend\zend_execute_api.c @ 821]	  c:\php-sdk\phpmaster\vc15\x64\php-src\zend\zend_execute_api.c @ 821
php7ts_debug!zephir_call_user_func_array_noex+160 [c:\php-sdk\phpmaster\vc15\x64\pecl\phalcon\phalcon.zep.c @ 8576]	  c:\php-sdk\phpmaster\vc15\x64\pecl\phalcon\phalcon.zep.c @ 8576
php7ts_debug!zephir_call_user_func_array+45 [c:\php-sdk\phpmaster\vc15\x64\pecl\phalcon\phalcon.zep.c @ 2856 + 14]	  c:\php-sdk\phpmaster\vc15\x64\pecl\phalcon\phalcon.zep.c @ 2856 + 14
php7ts_debug!zim_Phalcon_Dispatcher_callActionMethod+570 [c:\php-sdk\phpmaster\vc15\x64\pecl\phalcon\phalcon.zep.c @ 18413 + 17]	  c:\php-sdk\phpmaster\vc15\x64\pecl\phalcon\phalcon.zep.c @ 18413 + 17
php7ts_debug!zend_call_function+108b [c:\php-sdk\phpmaster\vc15\x64\php-src\zend\zend_execute_api.c @ 835]	  c:\php-sdk\phpmaster\vc15\x64\php-src\zend\zend_execute_api.c @ 835
php7ts_debug!zephir_call_user_function+6b2 [c:\php-sdk\phpmaster\vc15\x64\pecl\phalcon\phalcon.zep.c @ 8380 + 12]	  c:\php-sdk\phpmaster\vc15\x64\pecl\phalcon\phalcon.zep.c @ 8380 + 12
php7ts_debug!zephir_call_class_method_aparams+159 [c:\php-sdk\phpmaster\vc15\x64\pecl\phalcon\phalcon.zep.c @ 8516 + 5f]	  c:\php-sdk\phpmaster\vc15\x64\pecl\phalcon\phalcon.zep.c @ 8516 + 5f
php7ts_debug!zim_Phalcon_Dispatcher_dispatch+6f66 [c:\php-sdk\phpmaster\vc15\x64\pecl\phalcon\phalcon.zep.c @ 18083 + 14a]	  c:\php-sdk\phpmaster\vc15\x64\pecl\phalcon\phalcon.zep.c @ 18083 + 14a
php7ts_debug!zend_call_function+108b [c:\php-sdk\phpmaster\vc15\x64\php-src\zend\zend_execute_api.c @ 835]	  c:\php-sdk\phpmaster\vc15\x64\php-src\zend\zend_execute_api.c @ 835
php7ts_debug!zephir_call_user_function+6b2 [c:\php-sdk\phpmaster\vc15\x64\pecl\phalcon\phalcon.zep.c @ 8380 + 12]	  c:\php-sdk\phpmaster\vc15\x64\pecl\phalcon\phalcon.zep.c @ 8380 + 12
php7ts_debug!zephir_call_class_method_aparams+159 [c:\php-sdk\phpmaster\vc15\x64\pecl\phalcon\phalcon.zep.c @ 8516 + 5f]	  c:\php-sdk\phpmaster\vc15\x64\pecl\phalcon\phalcon.zep.c @ 8516 + 5f
php7ts_debug!zim_Phalcon_Mvc_Application_handle+4f17 [c:\php-sdk\phpmaster\vc15\x64\pecl\phalcon\phalcon.zep.c @ 84599 + 113]	  c:\php-sdk\phpmaster\vc15\x64\pecl\phalcon\phalcon.zep.c @ 84599 + 113
php7ts_debug!ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER+3e3 [c:\php-sdk\phpmaster\vc15\x64\php-src\zend\zend_vm_execute.h @ 1033]	  c:\php-sdk\phpmaster\vc15\x64\php-src\zend\zend_vm_execute.h @ 1033
php7ts_debug!execute_ex+8d [c:\php-sdk\phpmaster\vc15\x64\php-src\zend\zend_vm_execute.h @ 59739 + f]	  c:\php-sdk\phpmaster\vc15\x64\php-src\zend\zend_vm_execute.h @ 59739 + f
php7ts_debug!zend_execute+1eb [c:\php-sdk\phpmaster\vc15\x64\php-src\zend\zend_vm_execute.h @ 63777]	  c:\php-sdk\phpmaster\vc15\x64\php-src\zend\zend_vm_execute.h @ 63777
php7ts_debug!zend_execute_scripts+10f [c:\php-sdk\phpmaster\vc15\x64\php-src\zend\zend.c @ 1497]	  c:\php-sdk\phpmaster\vc15\x64\php-src\zend\zend.c @ 1497
php7ts_debug!php_execute_script+7d5 [c:\php-sdk\phpmaster\vc15\x64\php-src\main\main.c @ 2590 + 2e]	  c:\php-sdk\phpmaster\vc15\x64\php-src\main\main.c @ 2590 + 2e
php7apache2_4!php_handler+83c [c:\php-sdk\phpmaster\vc15\x64\php-src\sapi\apache2handler\sapi_apache2.c @ 702]	  c:\php-sdk\phpmaster\vc15\x64\php-src\sapi\apache2handler\sapi_apache2.c @ 702
libhttpd!ap_run_handler+35	  
libhttpd!ap_invoke_handler+10f	  
libhttpd!ap_internal_redirect+36	  
mod_rewrite+545d	  
libhttpd!ap_run_handler+35	  
libhttpd!ap_invoke_handler+10f	  
libhttpd!ap_internal_redirect_handler+29a	  
libhttpd!ap_process_request+f	  
libhttpd!ap_byterange_filter+1581	  
libhttpd!ap_run_process_connection+35	  
libhttpd!ap_process_connection+45	  
libhttpd!ap_run_generate_log_id+3da0	  
kernel32!BaseThreadInitThunk+14	  
ntdll!RtlUserThreadStart+21

@dreamsxin
Copy link
Contributor

I can't see the problem from this information. If I can reproduce it from linux, I can write different code to test it.

@hakimio
Copy link

hakimio commented Mar 12, 2019

@dreamsxin Have you tried to run Phalcon CLI TS with pthreads / multiple threads?

@CameronHall
Copy link

@hakimio I've just tested this myself on PHP 7.3 CLI TS on Apline Linux and can confirm (not with pthreads) that the issue is not reproducible. If you're interested in how I tested let me know and I'll create a repo.

Right now, I'm creating a Windows 10 VM on Azure for @dreamsxin to play with.

@hakimio
Copy link

hakimio commented Mar 19, 2019

@CameronHall it has to be multi-threaded app, because the issue is with thread-safety.

@CameronHall
Copy link

CameronHall commented Mar 19, 2019 via email

@CameronHall
Copy link

@dreamsxin I sent you an email yesterday with the details to access the VM.

@dreamsxin
Copy link
Contributor

@CameronHall I will try.

@CameronHall
Copy link

@dreamsxin I believe the issue may haver to do with the zephir_deinitialize_memory method. Though I don't know enough about the PHP Internals to be sure. Do you have any ideas?

@dreamsxin
Copy link
Contributor

Maybe double free the zval.

@dreamsxin
Copy link
Contributor

dreamsxin commented Apr 16, 2019

Can't reproduce

  • OS: Ubuntu 16

  • PHP: 7.0-zts

  • Zephir: 0.11.12

  • Apache: Apache/2.4.18

  • Server API | Apache 2.0 Handler

  • Zend Extension Build | API320151012,TS

  • PHP Extension Build | API20151012,TS

Zephir code:

namespace Test;

class app
{
	public function __construct()
	{
		var di;
		let di = Di::getInstance();
	}
}
namespace Test;

class Di
{
	private static _default;

	public static function getInstance()
	{
		var di;
		let di = self::_default;

		if !di {
			let di = new self();
			let self::_default = di;
		}

		return self::_default;
	}
}

@hakimio
Copy link

hakimio commented Apr 16, 2019

@dreamsxin didn't @CameronHall already provide you with a VM you can use for testing?

@dreamsxin
Copy link
Contributor

dreamsxin commented Apr 16, 2019

I just had this problem with Phalcon 3.4, use Zephir/development regenerate code,the problem solving.

git clone https://github.com/dreamsxin/zephir.git
git fetch origin
git checkout origin/phalcon_3.4 -f

cd cphalcon-3.4
../zephir/zephir fullclean
../zephir/zephir generate
cd ext/
make -j4 && make install

test.php

<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
$di = new Phalcon\DI\FactoryDefault;
echo "ok".PHP_EOL;
ab -v2 -n 1000 -c 50 http://localhost/test.php

@sergeyklay
Copy link
Contributor

Closing, this is fixed. If there are bugs, we can follow up in separate issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests