Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'internal/praefect/datastore/listener_postgres.go')
-rw-r--r--internal/praefect/datastore/listener_postgres.go12
1 files changed, 10 insertions, 2 deletions
diff --git a/internal/praefect/datastore/listener_postgres.go b/internal/praefect/datastore/listener_postgres.go
index edaba97d3..9c45f3537 100644
--- a/internal/praefect/datastore/listener_postgres.go
+++ b/internal/praefect/datastore/listener_postgres.go
@@ -88,6 +88,7 @@ func NewPostgresListener(logger logrus.FieldLogger, opts PostgresListenerOpts, h
func (pgl *PostgresListener) connect() error {
firstConnectionAttempt := true
connectErrChan := make(chan error, 1)
+ listenerAssignedChan := make(chan struct{})
connectionLifecycle := func(eventType pq.ListenerEventType, err error) {
pgl.reconnectTotal.WithLabelValues(listenerEventTypeToString(eventType)).Inc()
@@ -107,8 +108,14 @@ func (pgl *PostgresListener) connect() error {
// once the connection is established we can be sure that the connection
// address is correct and all other errors could be considered as
// a temporary, so listener will try to re-connect and proceed.
- pgl.async(pgl.ping)
- pgl.async(pgl.handleNotifications)
+ pgl.async(func() {
+ <-listenerAssignedChan
+ pgl.ping()
+ })
+ pgl.async(func() {
+ <-listenerAssignedChan
+ pgl.handleNotifications()
+ })
close(connectErrChan) // to signal the connection was established without troubles
firstConnectionAttempt = false
@@ -123,6 +130,7 @@ func (pgl *PostgresListener) connect() error {
}
pgl.listener = pq.NewListener(pgl.opts.Addr, pgl.opts.MinReconnectInterval, pgl.opts.MaxReconnectInterval, connectionLifecycle)
+ close(listenerAssignedChan)
listenErrChan := make(chan error, 1)
pgl.async(func() {