Bug 34723 - Traceback in pkgdb when postgres not running
Traceback in pkgdb when postgres not running
Status: CLOSED FIXED
Product: UCS
Classification: Unclassified
Component: pkgdb
UCS 3.2
Other Linux
: P5 normal (vote)
: UCS 3.2-2-errata
Assigned To: Lukas Walter
Janek Walkenhorst
:
Depends on:
Blocks: 35902
  Show dependency treegraph
 
Reported: 2014-05-01 00:54 CEST by Dirk Wiesenthal
Modified: 2014-09-11 14:50 CEST (History)
2 users (show)

See Also:
What kind of report is it?: ---
What type of bug is this?: ---
Who will be affected by this bug?: ---
How will those affected feel about the bug?: ---
User Pain:
Enterprise Customer affected?:
School Customer affected?:
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number:
Bug group (optional): Error handling
Max CVSS v3 score:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dirk Wiesenthal univentionstaff 2014-05-01 00:54:15 CEST
Reported by traceback feedback:

 Traceback:
The init function of the module has failed: InternalError: could not connect to server: No
such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.6/univention/management/console/protocol/modserver.py",
line 228, in handle
    self.__handler.init()
  File
"/usr/lib/pymodules/python2.6/univention/management/console/modules/pkgdb/__init__.py",
line 210, in init
    self.connection = updb.open_database_connection(self.ucr, pkgdbu=True)
  File "/usr/lib/pymodules/python2.6/univention/pkgdb.py", line 521, in
open_database_connection
    connection = pgdb.connect(database=connectstring)
  File "/usr/lib/python2.6/dist-packages/pgdb.py", line 482, in connect
    dbtty, dbuser, dbpasswd)
InternalError: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
Comment 1 Dirk Wiesenthal univentionstaff 2014-05-12 11:40:45 CEST
Happened at least 3 more times
Comment 2 Lukas Walter univentionstaff 2014-06-17 17:59:42 CEST
The UMC did not yet offer a way to provide user friendly error messages on failed module init() calls.

A specific exception class (UMC_ModuleInitError) has been added which can be thrown by UMC modules with a proper error message. UMC won't display the traceback, but only the error message passed to this exception when catchting it.

svn 51145: univention-management-console (6.0.26-6)



The pkgdb UMC module will throw an UMC_MOduleInitError, informing the user about the fact that the database server could not be contacted.

svn 51146: univention-pkgdb (7.0.11-2)

univention-pkgdb: yet to be build, YAML needs to be commited.
Comment 3 Florian Best univentionstaff 2014-06-18 08:29:06 CEST
FYI: It doesn't make sense to translate the error message in the init() function because we don't have the information which language the user wants yet.

Your commit message contained bug number #33673 which is already CLOSED.
Comment 4 Lukas Walter univentionstaff 2014-06-18 17:56:40 CEST
> univention-pkgdb: yet to be build, YAML needs to be commited.

Build, YAML added (svn 51187)

Changes made for univention-pkgdb depend on changes made for univention-management-console. Therefore, the errata update for univention-pkgdb may not me published before.
Comment 5 Dirk Wiesenthal univentionstaff 2014-06-19 12:12:47 CEST
I am now getting errors when using the command line. This can probably be worked around by importing some modules in the correct order (at least I hope that this gives not always a traceback...). But there are scripts out there that were written before this was necessary.

>>> from univention.management.console.modules.appcenter.app_center import *
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/pymodules/python2.6/univention/management/console/modules/__init__.py", line 133, in <module>
    from ..protocol import Response, MIMETYPE_JSON
  File "/usr/lib/pymodules/python2.6/univention/management/console/protocol/__init__.py", line 192, in <module>
    from modserver import *
  File "/usr/lib/pymodules/python2.6/univention/management/console/protocol/modserver.py", line 46, in <module>
    from ..modules import UMC_ModuleInitError
ImportError: cannot import name UMC_ModuleInitError
Comment 6 Dirk Wiesenthal univentionstaff 2014-06-19 12:29:06 CEST
With a prepending

  from univention.management.console.protocol import *

it seems to work... But this is not a good solution

Also: I do not see why one needs a special UMC_ModuleInitError for that. UMC_Error would suffice (as these are raised manually AFAICS). From the changeset I would say that now we are losing information in case e != UMC_ModuleInitError. Why not revert and just:

)
+ if isinstance(e, UMC_Error):
+   error = str(e)
self.__init_error_message = error

(Haven't tested it)

Just thinking: If locale is not ready when raising in init() of the module, one may translate the error message _again_ in protocol/modserver.py with the correct translation object (as the modserver should now which locale it was about to set).
Comment 7 Lukas Walter univentionstaff 2014-06-19 15:01:28 CEST
> Also: I do not see why one needs a special UMC_ModuleInitError for that.
> UMC_Error would suffice (as these are raised manually AFAICS). 

We're over using UMC_Error around the modules, as (considering the name) it should be raised in case of a problem with the UMC itself but not with the modules.

We're over using UMC_Error around the modules, as (considering the name) it should be raised in case of a problem with the UMC itself but not with the modules.

> From the
> changeset I would say that now we are losing information in case e !=
> UMC_ModuleInitError.

No information is lost. The full traceback is shown in a feedback dialog when the caught exception is no instance of UMC_ModuleInitError. If the exception IS an instance of UMC_ModuleInitError, only the exception message is shown (without a full feedback dialog). In any case, the traceback gets logged.

That is to say: the modules have won a way to react to known errors in a user suitable way, while they can still force a feed back dialog by raising another exception type (e.g. "Exception", "ValueError", "TypeError").


Arbitrament?
Comment 8 Lukas Walter univentionstaff 2014-06-19 15:02:43 CEST
> We're over using UMC_Error around the modules, as (considering the name) it
> should be raised in case of a problem with the UMC itself but not with the
> modules.

Copy&Paste error.
Comment 9 Lukas Walter univentionstaff 2014-06-20 13:21:43 CEST
(In reply to Dirk Wiesenthal from comment #5)
> I am now getting errors when using the command line. This can probably be
> worked around by importing some modules in the correct order (at least I
> hope that this gives not always a traceback...). But there are scripts out
> there that were written before this was necessary.
> 
> >>> from univention.management.console.modules.appcenter.app_center import *
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File
> "/usr/lib/pymodules/python2.6/univention/management/console/modules/__init__.
> py", line 133, in <module>
>     from ..protocol import Response, MIMETYPE_JSON
>   File
> "/usr/lib/pymodules/python2.6/univention/management/console/protocol/
> __init__.py", line 192, in <module>
>     from modserver import *
>   File
> "/usr/lib/pymodules/python2.6/univention/management/console/protocol/
> modserver.py", line 46, in <module>
>     from ..modules import UMC_ModuleInitError
> ImportError: cannot import name UMC_ModuleInitError

Circular import. Fixed by defering the import.

svn 51213: univention-management-console (6.0.24-13)
Comment 10 Janek Walkenhorst univentionstaff 2014-06-30 16:33:51 CEST
If the server is stopped while the module is active the module process remains running and the user is given the wrong feedback. (Empty results instead of error message)
Comment 11 Lukas Walter univentionstaff 2014-07-01 18:37:10 CEST
(In reply to Janek Walkenhorst from comment #10)
> If the server is stopped while the module is active the module process
> remains running and the user is given the wrong feedback. (Empty results
> instead of error message)

Right now, the API offered by univention-pkgdb, which is used in the univention-pkgdb UMC module, does not provide a way for higher code levels to evaluate whether an error occured or not - exceptions are logged and swallowed, empty results given back.

Therefore, the only clean way to fix this issue is by changing this API in a way that, for examples, passes exceptions along.

Alternatively, we could perform a simple request to the database for each query the module gets, bypassing the API, just to ensure that the server is still running.
Comment 12 Lukas Walter univentionstaff 2014-07-02 16:50:50 CEST
(In reply to Dirk Wiesenthal from comment #6)
> Also: I do not see why one needs a special UMC_ModuleInitError for that.
> UMC_Error would suffice (as these are raised manually AFAICS)

UMC_Error/UMC_CommandError will be used.


(In reply to Lukas Walter from comment #11)
> Alternatively, we could perform a simple request to the database for each
> query the module gets, bypassing the API, just to ensure that the server is
> still running.

Implemented.
Comment 13 Dirk Wiesenthal univentionstaff 2014-07-02 17:26:58 CEST
Typo: Connection to the dabase lost

Also: self.dbConnection is camelcase, one should use db_connection. But in this case it should actually be connection: self.connection was there before the patch. Now this (kind of) public member is gone.
Comment 14 Lukas Walter univentionstaff 2014-07-03 12:13:25 CEST
(In reply to Dirk Wiesenthal from comment #13)
> Typo: Connection to the dabase lost
> 
> Also: self.dbConnection is camelcase, one should use db_connection. But in
> this case it should actually be connection: self.connection was there before
> the patch. Now this (kind of) public member is gone.


I've fixed the typo and renamed the attributes.

svn 51475: univention-pkgdb (7.0.11-6)
Comment 15 Florian Best univentionstaff 2014-07-11 15:25:50 CEST
Missing XS-Python-Version:

Trigger für python-support werden verarbeitet ...
/usr/lib/pymodules/python2.5/univention/management/console/modules/pkgdb/__init__.py:229: Warning: 'as' will become a reserved keyword in Python 2.6
Compiling /usr/lib/pymodules/python2.5/univention/management/console/modules/pkgdb/__init__.py ...
  File "/usr/lib/pymodules/python2.5/univention/management/console/modules/pkgdb/__init__.py", line 229
    except pgdb.InternalError as ex:
                               ^
SyntaxError: invalid syntax
Comment 16 Janek Walkenhorst univentionstaff 2014-08-01 16:17:47 CEST
(In reply to Janek Walkenhorst from comment #10)
> If the server is stopped while the module is active the module process
> remains running and the user is given the wrong feedback. (Empty results
> instead of error message)
This works now.
Also if the server is already not running when starting the module; A helpful message is shown.

Advisory: OK
Comment 17 Janek Walkenhorst univentionstaff 2014-08-07 17:42:11 CEST
http://errata.univention.de/ucs/3.2/159.html
Comment 18 Janek Walkenhorst univentionstaff 2014-08-07 17:48:43 CEST
http://errata.univention.de/ucs/3.2/171.html
Comment 19 Florian Best univentionstaff 2014-09-08 10:05:04 CEST
This fix introduced Bug #35700.