Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recreate listener if error is occured #236

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

clyang82
Copy link
Contributor

@clyang82 clyang82 commented Dec 18, 2024

recreate the listener when the notify is nil or there is an error for Ping()
here is the document for notify is nil

A notification channel will remain open until Unlisten is called, though connection loss might
result in some notifications being lost. To solve this problem, Listener sends
a nil pointer over the Notify channel any time the connection is re-established
following a connection loss. The application can get information about the
state of the underlying connection by setting an event callback in the call to
NewListener.

@clyang82 clyang82 changed the title [WIP] Recreate listener if error is occured Recreate listener if error is occured Jan 3, 2025
func (f *Default) NewListener(ctx context.Context, channel string, callback func(id string)) *pq.Listener {
logger := ocmlogger.NewOCMLogger(ctx)

listener := newListener(ctx, f.config, channel)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about new the listener in the goroutine waitForNotification? we can maintain the listener in one place, may like

func waitForNotification() {
   listener := newListener(ctx, f.config, channel)
   for {
     		// ...	
		// recreate the listener
		listener = newListener(ctx, dbConfig, channel)
        }
    }
}

Signed-off-by: clyang82 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants