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

Better errors for ResponseHandler and cancel ACK and response waits on disconnect #64

Merged
merged 17 commits into from
May 22, 2024

Conversation

javiercr
Copy link
Member

@javiercr javiercr commented May 19, 2024

Context

This PR continues the work on #63 (and should be merged after that one).

Description

Given the following sequence diagram for sending a Message:

If a message is sent by the user, right an instant before a connection refresh start, the message will be delivered by Meta after receiving our PUBLISH (/ls_req) (1) packet.

However the connection refresh could be closing the socket before Meta's PUBACK (2), or the PUBLISH(/ls_resp) (3) are received by us.

In that scenario, the makeLSRequest will be locked until the timeout defined in ResponseHandler.waitForDetails is triggered.

This PR changes that behavior by exposing the Context used by Client, so that whenever that Context is cancelled (by calling stopCurrentConnection), we also notify ResponseHandler.waitForDetails.

This PR also changes the signature for: waitForPubACKDetails, waitForSubACKDetails, and waitForPubResponseDetails so that they return a different sentinel error depending on each scenario.

TO BE DISCUSSED:

We need to discuss how to handle the new ErrContextCancelled in Portal.handleMatrixMessage. With the current implementation in this PR, the sent message will still be flagged as "Not delivered" in Beeper, despite having been delivered properly.

@javiercr javiercr requested a review from tulir May 19, 2024 16:14
@@ -21,7 +21,7 @@ func (c *Client) ExecuteTasks(tasks ...socket.Task) (*table.LSTable, error) {

resp, err := c.socket.makeLSRequest(payload, 3)
if err != nil {
return nil, fmt.Errorf("failed to send LS request: %v", err)
return nil, err
Copy link
Member Author

Choose a reason for hiding this comment

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

Heads up: this is gonna cause changes in the log files / records for users of the bridge, including Beeper infra. As the error strings will be different now.

case <-time.After(packetTimeout):
p.deleteDetails(packetId, channelType)
// TODO this should probably be an error
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 guess the TODO comment here was right :)

Copy link
Member

@tulir tulir left a comment

Choose a reason for hiding this comment

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

Some minor nitpicks

javiercr and others added 6 commits May 20, 2024 11:52
@javiercr javiercr requested a review from tulir May 20, 2024 10:04
@javiercr javiercr requested a review from tulir May 21, 2024 13:23
Copy link
Member

@tulir tulir left a comment

Choose a reason for hiding this comment

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

Looks like this should work now

Base automatically changed from feature/improve-sending-while-reconnecting to main May 22, 2024 08:32
@javiercr javiercr merged commit 74a5063 into main May 22, 2024
11 checks passed
@javiercr javiercr deleted the feature/better-response-handler-errors branch May 22, 2024 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants