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

Generalized notif stream #826

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

sputn1ck
Copy link
Member

This PR adds a generalized notif stream that replaces specific streams such as the reservations listener.

Copy link
Collaborator

@starius starius left a comment

Choose a reason for hiding this comment

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

LGTM 🎉

Great work! I like the oneof approach in schema.
Left few suggestions.

notifications/log.go Outdated Show resolved Hide resolved
notifications/manager.go Outdated Show resolved Hide resolved
notifications/manager.go Outdated Show resolved Hide resolved
notifications/manager.go Outdated Show resolved Hide resolved
notifications/manager.go Outdated Show resolved Hide resolved
notifications/manager.go Outdated Show resolved Hide resolved
notifications/manager.go Show resolved Hide resolved
notifications/manager.go Show resolved Hide resolved
loopd/daemon.go Outdated Show resolved Hide resolved
@sputn1ck sputn1ck force-pushed the generalized_notif_stream branch 3 times, most recently from e8ddc78 to 0bc48d0 Compare September 19, 2024 18:55
Copy link
Collaborator

@starius starius left a comment

Choose a reason for hiding this comment

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

Few suggestions

notifications/manager.go Outdated Show resolved Hide resolved
notifications/manager.go Outdated Show resolved Hide resolved
notifications/manager.go Show resolved Hide resolved
notifications/manager.go Show resolved Hide resolved
notifications/manager.go Outdated Show resolved Hide resolved
notifications/manager.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@starius starius left a comment

Choose a reason for hiding this comment

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

LGTM 🌴
Final micro-nits

notifications/manager.go Outdated Show resolved Hide resolved
select {
case <-sub.subCtx.Done():
close(recvChan)
continue
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should it be break here? Otherwise we can close recvChan multiple times (panic).

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's correct with continue. My linter highlights the for loop if I have this continue selected 😆
image

Copy link
Collaborator

Choose a reason for hiding this comment

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

You are right! I confused sub.subCtx with ctx :)


select {
case <-time.After(10 * time.Second):
return fmt.Errorf("notification manager not ready")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is 10 seconds sufficient? If L402 fails and retries, fetchL402 already waits for 10 seconds, so it will crash here by the time of the second attempt. Also in Tor 10 seconds is not enough.


cancel()
// Wait for a bit before reconnecting.
<-time.After(time.Second * 10)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I propose this:

select {
case <-time.After(time.Second * 10):
case <-ctx.Done():
}

not to keep this goroutine running for 10 seconds after main context is cancelled.

Copy link
Member Author

Choose a reason for hiding this comment

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

Have a new timer version up in a bit, which waits 0 seconds on the first try!

return nil
default:
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: I propose to move this code into a new method. Then we can defer cancel() in that method.

return notifChan
}

// Run starts the notification manager.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I propose to add to godoc, that it closes readyChan as soon as it makes first successful connection to the stream. Also worth noting, that the function is long-running (not launching a goroutine and returning soon).

@sputn1ck sputn1ck force-pushed the generalized_notif_stream branch 2 times, most recently from a4152d1 to d4a3f29 Compare September 19, 2024 20:40
This commit refactors the proto definitions of the
reservation notifications to use a more generic
mechanism that can be used for other types of
notifications as well.
This commit removes the notification stream from
the reservation manager and replaces it with a
subscriber interface.
@sputn1ck sputn1ck force-pushed the generalized_notif_stream branch 2 times, most recently from 666edcd to 882c010 Compare September 22, 2024 09:23
@sputn1ck sputn1ck marked this pull request as ready for review September 22, 2024 09:23
This commit adds a generic notification manager
that can be used to subscribe to different types
of notifications.
This commit adds the notification manager to the
loopd daemon.
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