Thread: [pgAdmin4][Patch]: RM #3277 Runtime startup error handling is brokenon Windows.

Hi Hackers,

Please find the attached patch to fix RM #3277 Runtime startup error handling is broken on Windows.

This issue is regression of RM #3177 "Sporadically crashes on Windows when exit". Where below code of pgAdmin4.cpp creates the problem:
QObject::connect(server, SIGNAL(finished()), server, SLOT(deleteLater()));

In case when PythonPath is not provided then application server not started and server thread finished there execution, due to the above line of code Destructor of Server class has been called and we are accessing the function server->getError().length() at line no 251 of pgAdmin4.cpp, which cause the application crash.

I have removed that line and tested RM #3177 and RM# 3277, both are working fine.

Please review and test it.

--
Akshay Joshi
Sr. Software Architect


Phone: +91 20-3058-9517
Mobile: +91 976-788-8246
Attachment
Hi

On Thu, May 10, 2018 at 2:00 PM, Akshay Joshi <akshay.joshi@enterprisedb.com> wrote:
Hi Hackers,

Please find the attached patch to fix RM #3277 Runtime startup error handling is broken on Windows.

This issue is regression of RM #3177 "Sporadically crashes on Windows when exit". Where below code of pgAdmin4.cpp creates the problem:
QObject::connect(server, SIGNAL(finished()), server, SLOT(deleteLater()));

In case when PythonPath is not provided then application server not started and server thread finished there execution, due to the above line of code Destructor of Server class has been called and we are accessing the function server->getError().length() at line no 251 of pgAdmin4.cpp, which cause the application crash.

I have removed that line and tested RM #3177 and RM# 3277, both are working fine.

Please review and test it.

So my first test was compiled against Python 3, but my config was still pointing at a Python 2 venv. I got the error below in the console of QtCreator.

Also, wouldn't it make more sense to move the connect that you removed so it only happens once the server is up and running? That way we will still ensure it gets properly deleted when appropriate, but not prematurely if an error occurs during startup.

 Starting /Users/dpage/git/pgadmin4/build-pgAdmin4-Desktop_Qt_5_10_1_clang_64bit-Debug/pgAdmin4.app/Contents/MacOS/pgAdmin4...
Python path:  "/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/site-packages:/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7" 
Python Home:  ""
Fatal Python error: Py_Initialize: unable to load the file system codec
  File "/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/encodings/__init__.py", line 123
    raise CodecRegistryError,\
                            ^
SyntaxError: invalid syntax

Current thread 0x00007fffcbb433c0 (most recent call first):
The program has unexpectedly finished.
/Users/dpage/git/pgadmin4/build-pgAdmin4-Desktop_Qt_5_10_1_clang_64bit-Debug/pgAdmin4.app/Contents/MacOS/pgAdmin4 crashed.

Starting /Users/dpage/git/pgadmin4/build-pgAdmin4-Desktop_Qt_5_10_1_clang_64bit-Debug/pgAdmin4.app/Contents/MacOS/pgAdmin4...
Python path:  "/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/site-packages:/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7" 
Python Home:  ""
Fatal Python error: Py_Initialize: unable to load the file system codec
  File "/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/encodings/__init__.py", line 123
    raise CodecRegistryError,\
                            ^
SyntaxError: invalid syntax

Current thread 0x00007fffcbb433c0 (most recent call first):
The program has unexpectedly finished.
/Users/dpage/git/pgadmin4/build-pgAdmin4-Desktop_Qt_5_10_1_clang_64bit-Debug/pgAdmin4.app/Contents/MacOS/pgAdmin4 crashed.

--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
Hi

On Thu, May 10, 2018 at 7:38 PM, Dave Page <dpage@pgadmin.org> wrote:
Hi

On Thu, May 10, 2018 at 2:00 PM, Akshay Joshi <akshay.joshi@enterprisedb.com> wrote:
Hi Hackers,

Please find the attached patch to fix RM #3277 Runtime startup error handling is broken on Windows.

This issue is regression of RM #3177 "Sporadically crashes on Windows when exit". Where below code of pgAdmin4.cpp creates the problem:
QObject::connect(server, SIGNAL(finished()), server, SLOT(deleteLater()));

In case when PythonPath is not provided then application server not started and server thread finished there execution, due to the above line of code Destructor of Server class has been called and we are accessing the function server->getError().length() at line no 251 of pgAdmin4.cpp, which cause the application crash.

I have removed that line and tested RM #3177 and RM# 3277, both are working fine.

Please review and test it.

So my first test was compiled against Python 3, but my config was still pointing at a Python 2 venv. I got the error below in the console of QtCreator.

Also, wouldn't it make more sense to move the connect that you removed so it only happens once the server is up and running? That way we will still ensure it gets properly deleted when appropriate, but not prematurely if an error occurs during startup.

   Agreed, I have move that call to other place when server is up and running. Attached is the modified patch.  

 Starting /Users/dpage/git/pgadmin4/build-pgAdmin4-Desktop_Qt_5_10_1_clang_64bit-Debug/pgAdmin4.app/Contents/MacOS/pgAdmin4...
Python path:  "/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/site-packages:/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7" 
Python Home:  ""
Fatal Python error: Py_Initialize: unable to load the file system codec
  File "/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/encodings/__init__.py", line 123
    raise CodecRegistryError,\
                            ^
SyntaxError: invalid syntax

Current thread 0x00007fffcbb433c0 (most recent call first):
The program has unexpectedly finished.
/Users/dpage/git/pgadmin4/build-pgAdmin4-Desktop_Qt_5_10_1_clang_64bit-Debug/pgAdmin4.app/Contents/MacOS/pgAdmin4 crashed.

Starting /Users/dpage/git/pgadmin4/build-pgAdmin4-Desktop_Qt_5_10_1_clang_64bit-Debug/pgAdmin4.app/Contents/MacOS/pgAdmin4...
Python path:  "/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/site-packages:/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7" 
Python Home:  ""
Fatal Python error: Py_Initialize: unable to load the file system codec
  File "/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/encodings/__init__.py", line 123
    raise CodecRegistryError,\
                            ^
SyntaxError: invalid syntax

Current thread 0x00007fffcbb433c0 (most recent call first):
The program has unexpectedly finished.
/Users/dpage/git/pgadmin4/build-pgAdmin4-Desktop_Qt_5_10_1_clang_64bit-Debug/pgAdmin4.app/Contents/MacOS/pgAdmin4 crashed.

    Yes, it is reproducible. I have tried putting try catch around "Py_Initialize", but no success. 
    

--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company



--
Akshay Joshi
Sr. Software Architect


Phone: +91 20-3058-9517
Mobile: +91 976-788-8246
Attachment
Hi

On Fri, May 11, 2018 at 7:23 AM, Akshay Joshi <akshay.joshi@enterprisedb.com> wrote:
Hi

On Thu, May 10, 2018 at 7:38 PM, Dave Page <dpage@pgadmin.org> wrote:
Hi

On Thu, May 10, 2018 at 2:00 PM, Akshay Joshi <akshay.joshi@enterprisedb.com> wrote:
Hi Hackers,

Please find the attached patch to fix RM #3277 Runtime startup error handling is broken on Windows.

This issue is regression of RM #3177 "Sporadically crashes on Windows when exit". Where below code of pgAdmin4.cpp creates the problem:
QObject::connect(server, SIGNAL(finished()), server, SLOT(deleteLater()));

In case when PythonPath is not provided then application server not started and server thread finished there execution, due to the above line of code Destructor of Server class has been called and we are accessing the function server->getError().length() at line no 251 of pgAdmin4.cpp, which cause the application crash.

I have removed that line and tested RM #3177 and RM# 3277, both are working fine.

Please review and test it.

So my first test was compiled against Python 3, but my config was still pointing at a Python 2 venv. I got the error below in the console of QtCreator.

Also, wouldn't it make more sense to move the connect that you removed so it only happens once the server is up and running? That way we will still ensure it gets properly deleted when appropriate, but not prematurely if an error occurs during startup.

   Agreed, I have move that call to other place when server is up and running. Attached is the modified patch.  

Thanks, applied.
 

 Starting /Users/dpage/git/pgadmin4/build-pgAdmin4-Desktop_Qt_5_10_1_clang_64bit-Debug/pgAdmin4.app/Contents/MacOS/pgAdmin4...
Python path:  "/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/site-packages:/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7" 
Python Home:  ""
Fatal Python error: Py_Initialize: unable to load the file system codec
  File "/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/encodings/__init__.py", line 123
    raise CodecRegistryError,\
                            ^
SyntaxError: invalid syntax

Current thread 0x00007fffcbb433c0 (most recent call first):
The program has unexpectedly finished.
/Users/dpage/git/pgadmin4/build-pgAdmin4-Desktop_Qt_5_10_1_clang_64bit-Debug/pgAdmin4.app/Contents/MacOS/pgAdmin4 crashed.

Starting /Users/dpage/git/pgadmin4/build-pgAdmin4-Desktop_Qt_5_10_1_clang_64bit-Debug/pgAdmin4.app/Contents/MacOS/pgAdmin4...
Python path:  "/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/site-packages:/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7" 
Python Home:  ""
Fatal Python error: Py_Initialize: unable to load the file system codec
  File "/Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/encodings/__init__.py", line 123
    raise CodecRegistryError,\
                            ^
SyntaxError: invalid syntax

Current thread 0x00007fffcbb433c0 (most recent call first):
The program has unexpectedly finished.
/Users/dpage/git/pgadmin4/build-pgAdmin4-Desktop_Qt_5_10_1_clang_64bit-Debug/pgAdmin4.app/Contents/MacOS/pgAdmin4 crashed.

    Yes, it is reproducible. I have tried putting try catch around "Py_Initialize", but no success. 

Hmm, yeah - seems this is the problem:


Which is.. unfortunate.
 
--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company