Skip to content

Conversation

@vitaliy-io
Copy link
Contributor

No description provided.

defer c.reconnectMx.Unlock()
} else {
// already reconnecting, try again later
time.Sleep(50 * time.Millisecond)
Copy link
Collaborator

@nnikolash nnikolash Feb 4, 2025

Choose a reason for hiding this comment

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

If one thread hangs on reconnect, another will create 1 stack frame every 50ms, because e.g. writeMessage uses recursion after reconnect returns. Can this lead to stack overflow eventually?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess in theory we could run out of memory but it will only happen if L1 is not accessible for a really long time, which means that wasp will not be working anyway. Besides, golang's stack is more flexible and can grow dynamically. So I'm not sure if it's a major issue

log: log,
}

c.reconnect(ctx)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor thing, not a required fix: Maybe check an error? If context is canceled, if would be nice to return error, especially when we already have error returned from the contructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

err := c.CallContext(ctx, &subID, method, args...)
if err != nil {
c.log.Errorf("failed to resubscribe to %s: %s", method, err)
continue
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we should return here with error? Why would we support subscribing for part of all subscriptions? Wouldn't hta be a faulty state?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not sure. I though it makes sense to resubscribe to what we can anyway. Worst case scenario is that it just does not work

}

if c.conn != nil {
c.conn.Close()
Copy link
Collaborator

Choose a reason for hiding this comment

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

If read and write both will need to reconnect, would that mean that eventually they both will call this function?
I mean:

  1. read fail and tried to reconnect
  2. write fails and tries to reconnect but is required to wait for read to reconnect
  3. read reconnects -> resubscribes and recreated pending calls
  4. write "unfreezes" and is now also able to reconnect, and thus deletes again the connect (which might again trigger reconnect for read), and again resubscribes and recreates calls

I might be missing something

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this scenario is possible but is very unlikely, it could only happen if second flow (write in your case) calls reconnect RIGHT after the first reconnect finishes and the lock is released. In most cases second connection will just be waiting 50ms and then reconnect using new connection

@vitaliy-io
Copy link
Contributor Author

will address all questions/suggestions if we actually end up using this solution tomorrow

@vitaliy-io vitaliy-io closed this Feb 6, 2025
@vitaliy-io vitaliy-io reopened this Feb 6, 2025
@vitaliy-io vitaliy-io closed this Feb 6, 2025
@vitaliy-io vitaliy-io reopened this Feb 6, 2025
@vitaliy-io vitaliy-io marked this pull request as draft February 6, 2025 14:59
@vitaliy-io vitaliy-io marked this pull request as ready for review February 18, 2025 12:42
@lmoe lmoe merged commit 26f1825 into develop Feb 20, 2025
3 of 5 checks passed
@lmoe lmoe deleted the feature/ws-reconnect branch February 20, 2025 10:31
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.

5 participants