IguteChung / casbin-psql-watcher

A WatcherEX implementation for Casbin based on PostgreSQL
MIT License
8 stars 1 forks source link

Support connection recovery #2

Open condorcet opened 1 year ago

condorcet commented 1 year ago

Hi!

For now watcher cannot restore listening if Postgres connection is lost. https://github.com/IguteChung/casbin-psql-watcher/blob/main/watcher.go#L79

go func() {
        if err := w.listenMessage(listenerCtx); err == context.Canceled {
            log.Println("[psqlwatcher] watcher closed")
        } else if err != nil {
                        // after error we end up here and won't be able to receive any updates
            log.Printf("[psqlwatcher] failed to listen message: %v\n", err)
        }
    }()

But also if we restore listening after reconnect, we must trigger update policy implicitly, because some notifications may skipped at this moment. Postgres listen / notify has no guarantee about receiving notification if no body listen it.

hsluoyz commented 1 year ago

@IguteChung