diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-10-25 11:44:04 +0200 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-10-25 11:44:04 +0200 |
| commit | b4be281671ecfe5c1e6f831614ca1dde48522cd7 (patch) | |
| tree | 60607908ae545d32aabc08d86d22444003744d65 | |
| parent | c9603e4a2ec682ca30399205ccbf533f55230ad4 (diff) | |
Client + FSM: Remove background argument from transition
This fixes a race condition reported by Go's -race flag
In the future we should use waitgroups to ensure the OAuth local listener is started before we sent the URL
| -rw-r--r-- | client/client.go | 4 | ||||
| -rw-r--r-- | client/fsm.go | 10 | ||||
| -rw-r--r-- | client/server.go | 20 | ||||
| -rw-r--r-- | internal/fsm/fsm.go | 10 |
4 files changed, 20 insertions, 24 deletions
diff --git a/client/client.go b/client/client.go index 5377801..0f9f536 100644 --- a/client/client.go +++ b/client/client.go @@ -119,7 +119,7 @@ func (client *Client) Register( } // Go to the No Server state with the saved servers after we're done - defer client.FSM.GoTransitionWithData(STATE_NO_SERVER, client.Servers, true) + defer client.FSM.GoTransitionWithData(STATE_NO_SERVER, client.Servers) // Let's Connect! doesn't care about discovery if client.isLetsConnect() { @@ -160,7 +160,7 @@ func (client *Client) askProfile(chosenServer server.Server) error { if profilesErr != nil { return types.NewWrappedError("failed asking for profiles", profilesErr) } - client.FSM.GoTransitionWithData(STATE_ASK_PROFILE, profiles, false) + client.FSM.GoTransitionWithData(STATE_ASK_PROFILE, profiles) return nil } diff --git a/client/fsm.go b/client/fsm.go index a1d82f7..767ceaa 100644 --- a/client/fsm.go +++ b/client/fsm.go @@ -292,7 +292,7 @@ func (client *Client) SetConnected() error { return client.handleError(errorMessage, currentServerErr) } - client.FSM.GoTransitionWithData(STATE_CONNECTED, currentServer, false) + client.FSM.GoTransitionWithData(STATE_CONNECTED, currentServer) return nil } @@ -321,7 +321,7 @@ func (client *Client) SetConnecting() error { return client.handleError(errorMessage, currentServerErr) } - client.FSM.GoTransitionWithData(STATE_CONNECTING, currentServer, false) + client.FSM.GoTransitionWithData(STATE_CONNECTING, currentServer) return nil } @@ -350,7 +350,7 @@ func (client *Client) SetDisconnecting() error { return client.handleError(errorMessage, currentServerErr) } - client.FSM.GoTransitionWithData(STATE_DISCONNECTING, currentServer, false) + client.FSM.GoTransitionWithData(STATE_DISCONNECTING, currentServer) return nil } @@ -385,7 +385,7 @@ func (client *Client) SetDisconnected(cleanup bool) error { server.Disconnect(currentServer) } - client.FSM.GoTransitionWithData(STATE_DISCONNECTED, currentServer, false) + client.FSM.GoTransitionWithData(STATE_DISCONNECTED, currentServer) return nil } @@ -414,7 +414,7 @@ func (client *Client) GoBack() error { } // FIXME: Abitrary back transitions don't work because we need the approriate data - client.FSM.GoTransitionWithData(STATE_NO_SERVER, client.Servers, false) + client.FSM.GoTransitionWithData(STATE_NO_SERVER, client.Servers) return nil } diff --git a/client/server.go b/client/server.go index 2274378..ee6ec11 100644 --- a/client/server.go +++ b/client/server.go @@ -90,7 +90,7 @@ func (client *Client) getConfig( } // Signal the server display info - client.FSM.GoTransitionWithData(STATE_DISCONNECTED, currentServer, false) + client.FSM.GoTransitionWithData(STATE_DISCONNECTED, currentServer) // Save the config saveErr := client.Config.Save(&client) @@ -142,7 +142,7 @@ func (client *Client) RemoveSecureInternet() error { } // No error because we can only have one secure internet server and if there are no secure internet servers, this is a NO-OP client.Servers.RemoveSecureInternet() - client.FSM.GoTransitionWithData(STATE_NO_SERVER, client.Servers, false) + client.FSM.GoTransitionWithData(STATE_NO_SERVER, client.Servers) // Save the config saveErr := client.Config.Save(&client) if saveErr != nil { @@ -168,7 +168,7 @@ func (client *Client) RemoveInstituteAccess(url string) error { } // No error because this is a NO-OP if the server doesn't exist client.Servers.RemoveInstituteAccess(url) - client.FSM.GoTransitionWithData(STATE_NO_SERVER, client.Servers, false) + client.FSM.GoTransitionWithData(STATE_NO_SERVER, client.Servers) // Save the config saveErr := client.Config.Save(&client) if saveErr != nil { @@ -194,7 +194,7 @@ func (client *Client) RemoveCustomServer(url string) error { } // No error because this is a NO-OP if the server doesn't exist client.Servers.RemoveCustomServer(url) - client.FSM.GoTransitionWithData(STATE_NO_SERVER, client.Servers, false) + client.FSM.GoTransitionWithData(STATE_NO_SERVER, client.Servers) // Save the config saveErr := client.Config.Save(&client) if saveErr != nil { @@ -253,7 +253,7 @@ func (client *Client) AddInstituteServer(url string) (server.Server, error) { return nil, client.handleError(errorMessage, loginErr) } - client.FSM.GoTransitionWithData(STATE_NO_SERVER, client.Servers, false) + client.FSM.GoTransitionWithData(STATE_NO_SERVER, client.Servers) return server, nil } @@ -312,7 +312,7 @@ func (client *Client) AddSecureInternetHomeServer(orgID string) (server.Server, _ = client.RemoveSecureInternet() return nil, client.handleError(errorMessage, loginErr) } - client.FSM.GoTransitionWithData(STATE_NO_SERVER, client.Servers, false) + client.FSM.GoTransitionWithData(STATE_NO_SERVER, client.Servers) return server, nil } @@ -359,7 +359,7 @@ func (client *Client) AddCustomServer(url string) (server.Server, error) { return nil, client.handleError(errorMessage, loginErr) } - client.FSM.GoTransitionWithData(STATE_NO_SERVER, client.Servers, false) + client.FSM.GoTransitionWithData(STATE_NO_SERVER, client.Servers) return server, nil } @@ -483,7 +483,7 @@ func (client *Client) askSecureLocation() error { locations := client.Discovery.GetSecureLocationList() // Ask for the location in the callback - client.FSM.GoTransitionWithData(STATE_ASK_LOCATION, locations, false) + client.FSM.GoTransitionWithData(STATE_ASK_LOCATION, locations) // The state has changed, meaning setting the secure location was not successful if client.FSM.Current != STATE_ASK_LOCATION { @@ -518,7 +518,7 @@ func (client *Client) ChangeSecureLocation() error { } // Go back to the main screen - client.FSM.GoTransitionWithData(STATE_NO_SERVER, client.Servers, false) + client.FSM.GoTransitionWithData(STATE_NO_SERVER, client.Servers) return nil } @@ -577,7 +577,7 @@ func (client *Client) ensureLogin(chosenServer server.Server) error { if server.NeedsRelogin(chosenServer) { url, urlErr := server.GetOAuthURL(chosenServer, client.Name) - client.FSM.GoTransitionWithData(STATE_OAUTH_STARTED, url, true) + client.FSM.GoTransitionWithData(STATE_OAUTH_STARTED, url) if urlErr != nil { client.goBackInternal() diff --git a/internal/fsm/fsm.go b/internal/fsm/fsm.go index d5957b0..198d51a 100644 --- a/internal/fsm/fsm.go +++ b/internal/fsm/fsm.go @@ -110,7 +110,7 @@ func (fsm *FSM) GoBack() { fsm.GoTransition(fsm.States[fsm.Current].BackState) } -func (fsm *FSM) GoTransitionWithData(newState FSMStateID, data interface{}, background bool) bool { +func (fsm *FSM) GoTransitionWithData(newState FSMStateID, data interface{}) bool { ok := fsm.HasTransition(newState) if ok { @@ -120,18 +120,14 @@ func (fsm *FSM) GoTransitionWithData(newState FSMStateID, data interface{}, back fsm.writeGraph() } - if background { - go fsm.StateCallback(oldState, newState, data) - } else { - fsm.StateCallback(oldState, newState, data) - } + fsm.StateCallback(oldState, newState, data) } return ok } func (fsm *FSM) GoTransition(newState FSMStateID) bool { - return fsm.GoTransitionWithData(newState, "{}", false) + return fsm.GoTransitionWithData(newState, "{}") } func (fsm *FSM) generateMermaidGraph() string { |
