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

Add connection Reconnect method #18

Closed
wants to merge 6 commits into from

Conversation

ashton-herrington
Copy link
Contributor

@ashton-herrington ashton-herrington commented Sep 12, 2022

Currently if a connection goes offline, there is no way to re-estalbish this entire connection because the Connect method will see the existing net.Conn object in c.conn on these lines and use the existing (and closed) connection.

@ashton-herrington
Copy link
Contributor Author

I will include unit tests if this approach is approved

@ashton-herrington
Copy link
Contributor Author

Alternative approach would be to nil out the c.conn, I felt this was a bit safer as it didnt impact existing code

connection.go Outdated Show resolved Hide resolved
connection.go Outdated
return fmt.Errorf("connecting to server %s: %w", c.Addr, err)
}

c.conn = conn
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to worry about concurrent calls to Reconnect?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If used in a sane fashion? no, since it is a library that clients can do anything with? probably.

probably better idea to guard with a mutex, Ill add

require.NoError(t, c.Close())
})

t.Run("reconnect called on closed connection", func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

let's add one more test when the connection was closed by the server and we call Reconnect (without calling Close(). I guess this is how we are going to use inside brand-gateway.

Here is how we can ask servier to close the connection:

// trigger server to close connection

Choose a reason for hiding this comment

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

Are you referring to triggering <-done before the goroutine reaches it?

@alovak
Copy link
Contributor

alovak commented Oct 4, 2022

closing it for now. if we want to return to it, we can re-open PR

@alovak alovak closed this Oct 4, 2022
@alovak alovak deleted the CAR-814-add-reconnect-option branch September 1, 2023 21:29
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.

None yet

4 participants