Francois Gouget : testbot: Try to reconnect to the database in case of error.
Module: tools Branch: master Commit: ab9ab58d52ec99e12b2098cf81578020a9776bc5 URL: https://source.winehq.org/git/tools.git/?a=commit;h=ab9ab58d52ec99e12b2098cf... Author: Francois Gouget <fgouget(a)codeweavers.com> Date: Mon Jan 22 03:04:32 2018 +0100 testbot: Try to reconnect to the database in case of error. We set RaiseError in our DBI options so programming errors are easier to debug and have a better chance of being caught. However this means DBI::connect() will raise an exception if the database server is not running (like if it's being upgraded just at the wrong time). Furthermore the higher layers cannot meaningfully deal with a broken connection. So catch these exceptions and try reconnecting until successful. Signed-off-by: Francois Gouget <fgouget(a)codeweavers.com> Signed-off-by: Alexandre Julliard <julliard(a)winehq.org> --- testbot/lib/ObjectModel/DBIBackEnd.pm | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/testbot/lib/ObjectModel/DBIBackEnd.pm b/testbot/lib/ObjectModel/DBIBackEnd.pm index 4082a0a..0594951 100644 --- a/testbot/lib/ObjectModel/DBIBackEnd.pm +++ b/testbot/lib/ObjectModel/DBIBackEnd.pm @@ -53,9 +53,18 @@ sub GetDb($) } if (!defined $self->{Db}) { - $self->{Db} = DBI->connect(@{$self->{ConnectArgs}}); + while (1) + { + # Protect this call so we can retry in case RaiseError is set + eval { $self->{Db} = DBI->connect(@{$self->{ConnectArgs}}) }; + last if ($self->{Db}); + + # Prints errors on stderr like DBI normally does + $@ ||= "DBI::connect() returned undef without setting an error"; + print STDERR "$@\n"; + sleep(30); + } } - return $self->{Db}; }
participants (1)
-
Alexandre Julliard