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

use openvpn3 reconnect #590

Merged
merged 5 commits into from Dec 4, 2018
Merged

Conversation

zolia
Copy link
Contributor

@zolia zolia commented Nov 30, 2018

No description provided.

@zolia zolia requested a review from tadovas as a code owner November 30, 2018 12:13
@zolia zolia force-pushed the feature/MYST-580-use-openvpn3-reconnect branch from 284c789 to 4bc374b Compare November 30, 2018 12:14
@zolia zolia force-pushed the feature/MYST-580-use-openvpn3-reconnect branch 2 times, most recently from d45f50f to 0d45af3 Compare November 30, 2018 12:35
@zolia zolia force-pushed the feature/MYST-580-use-openvpn3-reconnect branch from 0d45af3 to c8b12a2 Compare November 30, 2018 13:40
mobile/mysterium/openvpn_connection_setup.go Outdated Show resolved Hide resolved
}

type sessionTracker struct {
session *openvpn3.Session
Copy link
Contributor

Choose a reason for hiding this comment

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

This reference is being set/read from possibly different threads. Some kind of sync mechanism is needed, like Mutex

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, added mutex

func (st *sessionTracker) handleState(stateEvent connection.StateEvent) {
// On disconnected - remove session
if stateEvent.State == connection.Disconnecting {
st.session.Stop()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
st.session.Stop()
st.session=nil

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

}

// Reconnect reconnects active session after given time
func (st *sessionTracker) Reconnect(afterSeconds int) error {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can use here golang native time.Duration to avoid future conversion?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

C.reconnect accepts int, so no conversion is needed. From mobile frameworks, more straight type is int too.


// Reconnect reconnects active session after given time
func (st *sessionTracker) Reconnect(afterSeconds int) error {
if st.session == nil {
Copy link
Member

Choose a reason for hiding this comment

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

Should we protect the reading of st.session if we are doing it in other places?

return errors.New("session not created yet")
}

return st.session.Reconnect(afterSeconds)
Copy link
Member

Choose a reason for hiding this comment

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

If this can be run in a multithread way, st.session can become nil after check above.
I'd protect the whole body of the function with a mutex.

func (st *sessionTracker) handleState(stateEvent connection.StateEvent) {
// On disconnected - remove session
if stateEvent.State == connection.Disconnecting {
st.session = nil
Copy link
Member

Choose a reason for hiding this comment

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

Should we protect st.session if we are doing it in other places?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

wrapped st.session modification between mutex.

mobile/mysterium/openvpn_connection_setup.go Show resolved Hide resolved
@zolia zolia force-pushed the feature/MYST-580-use-openvpn3-reconnect branch from 70605c0 to 13ab5f6 Compare December 3, 2018 11:10
@zolia zolia self-assigned this Dec 3, 2018
@@ -105,17 +105,21 @@ func (st *sessionTracker) sessionCreated(s *openvpn3.Session) {

// Reconnect reconnects active session after given time
func (st *sessionTracker) Reconnect(afterSeconds int) error {
st.mux.Lock()
if st.session == nil {
return errors.New("session not created yet")
Copy link
Contributor

Choose a reason for hiding this comment

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

if we return here(when the st.session is null, for example), the st.mux will never unlock now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point. Fixed.

@zolia zolia force-pushed the feature/MYST-580-use-openvpn3-reconnect branch from 90f3341 to 4b2c9cf Compare December 3, 2018 13:30
@zolia zolia merged commit 6261b28 into master Dec 4, 2018
@zolia zolia deleted the feature/MYST-580-use-openvpn3-reconnect branch December 4, 2018 10:47
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