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

feat: lazy websocket connection #393

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

jackstar12
Copy link
Member

only create actual websocket connection when there are pending swaps and
close it if there are no more pending swaps

@jackstar12 jackstar12 force-pushed the feat/lazy-websocket branch 2 times, most recently from 28949a4 to 00565e4 Compare February 13, 2025 18:47
only create actual websocket connection when there are pending swaps and
close it if there are no more pending swaps
Copy link
Member

@michael1011 michael1011 left a comment

Choose a reason for hiding this comment

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

It really feels like there should be locks on the pieces of code that touch the state of the websocket. The enum states that represent the state are not clear and the logic inside of the Connect function is getting way too complex and should be split up.

Comment on lines +73 to +75
if boltz.state == closed {
return errors.New("websocket is closed")
}
Copy link
Member

Choose a reason for hiding this comment

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

Why can't we connect again when a websocket was closed once?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because the close call also causes the updates channel to be closed. Its not closed in this call to avoid a situation where we just got a message in the receiving goroutine and would then send on a closed channel

@@ -201,6 +219,11 @@ func (boltz *Websocket) subscribe(swapIds []string) error {
}

func (boltz *Websocket) Subscribe(swapIds []string) error {
if boltz.state == disconnected {
if err := boltz.Connect(); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

There should be a check here for len(swapIds) > 0 to make sure that we don't open and close the websocket instantly afterwards

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