Bug 58159 - Password reset module does not reconnect to postgres DB if connection got lost
Summary: Password reset module does not reconnect to postgres DB if connection got lost
Status: CLOSED FIXED
Alias: None
Product: UCS
Classification: Unclassified
Component: Self Service
Version: UCS 5.2
Hardware: Other Linux
: P5 normal
Target Milestone: UCS 5.2-1-errata
Assignee: Florian Best
QA Contact: Johannes Lohmer
URL: https://git.knut.univention.de/univen...
Keywords:
Depends on:
Blocks:
 
Reported: 2025-04-02 13:03 CEST by Florian Best
Modified: 2025-07-30 11:38 CEST (History)
3 users (show)

See Also:
What kind of report is it?: Development Internal
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):
Customer ID:
Max CVSS v3 score:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Florian Best univentionstaff 2025-04-02 13:03:51 CEST
## Story

As a Administrator
I can expect that the UMC module `passwordreset` is able to reconnect to its postgres database in case the connection got lost,<br/>
so that I do not have to restart the UMC server every time the database has been restarted.

## Context/description

The UMC module `passwordreset` is using the postgres database to store the password reset tokens and their expiration time. For this, the UMC module 
establishes a connection to the database upon module startup. Unfortunately the module does not handle error cases that might occur in case the connection
to the DB got lost due to e.g. a database restart.

Currently the UMC module throws a traceback that is not caught by the UMC module. Additionally the UMC module does not try to reconnect to the database on its own. This mostly affects the method `send_token()` resp. `send_message()` of the UMC module.
Since the module might be used by several parties (selfservice listener in Nubus for k8s, humans using the UMC's password reset dialog, ...) on every request the timeout timer of the UMC module (by default 10min) is reset. The selfservice listener e.g. calls the UMC module every ~5min if there are items within its queue which keeps the UMC module and its broken state alive forever.

The UMC module should handle database errors on its own and try to reconnect if possible.

## Acceptance criteria

- [ ] The UMC module reconnects to the DB if necessary.
- [ ] A ucs-test has been implemented that checks the automatic reconnect.
Comment 1 Florian Best univentionstaff 2025-04-03 14:30:18 CEST
The connection to postgresql is checked before doing actions and tried to reconnect if that doesn't work.
A test case has been added.

univention-self-service.yaml
5627b3039f12 | fix(self-service): reconnect automatically to postgresql in case of connection loss

univention-self-service (7.1.1)
5627b3039f12 | fix(self-service): reconnect automatically to postgresql in case of connection loss

ucs-test (12.1.0)
f81c070bfe8d | test(self-service): check for database reconnection
Comment 2 Johannes Lohmer univentionstaff 2025-04-03 14:36:46 CEST
errata-yaml ok
test ok
reproduced ok
fixed ok
debian-package ok
fun ok
Comment 3 Felix Botner univentionstaff 2025-04-05 10:02:52 CEST
Not sure if there is a connection, but https://jenkins2022.knut.univention.de/job/UCS-5.2/job/UCS-5.2-1/job/AutotestJoin/lastCompletedBuild/SambaVersion=s4,Systemrolle=master-part-II/testReport/83_self_service/13_test_postgresql_connection_loss/test_reset_via_email/ (83_self_service
13_test_postgresql_connection_loss
test_reset_via_email) fails now.
Comment 4 Florian Best univentionstaff 2025-04-07 09:00:26 CEST
(In reply to Felix Botner from comment #3)
> Not sure if there is a connection, but
> https://jenkins2022.knut.univention.de/job/UCS-5.2/job/UCS-5.2-1/job/
> AutotestJoin/lastCompletedBuild/SambaVersion=s4,Systemrolle=master-part-II/
> testReport/83_self_service/13_test_postgresql_connection_loss/
> test_reset_via_email/ (83_self_service
> 13_test_postgresql_connection_loss
> test_reset_via_email) fails now.

The test case was introduced here. It failed due to the error message matched in pytest was german and not english.
It has been adjusted to detect both languages.

ucs-test (12.1.1)
c9df3f1e2866 | test(self-service): add support for german locale in 83_self_service/13_test_postgresql_connection_loss.py
Comment 5 Johannes Lohmer univentionstaff 2025-04-09 15:31:37 CEST
automated test-run: ok
packagebuild: ok
code-review: ok
Comment 6 Arvid Requate univentionstaff 2025-04-16 14:10:00 CEST
<https://errata.software-univention.de/#/?erratum=5.2x71>
Comment 7 Thomas Kintscher univentionstaff 2025-07-30 11:38:17 CEST
The fix was released as part of Nubus for Kubernetes 1.9.x as well.