-
Notifications
You must be signed in to change notification settings - Fork 20
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
fix: Fix to make mender-connect request a new JWT token on its own, so its not dependent on mender-update to do so #134
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -312,57 +312,51 @@ func (d *MenderShellDaemon) dbusEventLoop(client mender.AuthClient) { | |
break | ||
} | ||
|
||
if d.needsReconnect() { | ||
log.Trace("dbusEventLoop: daemon needs to reconnect") | ||
needsReconnect = true | ||
} | ||
|
||
p, err := client.WaitForJwtTokenStateChange() | ||
log.Tracef("dbusEventLoop: WaitForJwtTokenStateChange %v, err %v", p, err) | ||
|
||
if len(p) > 1 && | ||
p[0].ParamType == dbus.GDBusTypeString && | ||
p[1].ParamType == dbus.GDBusTypeString { | ||
|
||
token := p[0].ParamData.(string) | ||
serverURL := p[1].ParamData.(string) | ||
|
||
d.processJwtTokenStateChange(token, serverURL) | ||
if len(token) > 0 && len(serverURL) > 0 { | ||
log.Tracef("dbusEventLoop: got a token len=%d, ServerURL=%s", len(token), serverURL) | ||
if token != d.serverJwt || serverURL != d.serverUrl { | ||
log.Debugf( | ||
"dbusEventLoop: new token or ServerURL, reconnecting. len=%d, ServerURL=%s", | ||
len(token), | ||
serverURL, | ||
) | ||
needsReconnect = true | ||
e := MenderShellDaemonEvent{ | ||
event: EventReconnect, | ||
data: token, | ||
id: "(dbusEventLoop)", | ||
} | ||
d.serverJwt = token | ||
d.serverUrl = serverURL | ||
d.postEvent(e) | ||
log.Tracef("(dbusEventLoop) posting Event: %s", e.event) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Either we move this entry to before the |
||
needsReconnect = false | ||
|
||
// If the server (Mender client proxy) closed the connection, it is likely that | ||
// both messageLoop is asking for a reconnection and we got JwtTokenStateChange | ||
// signal. So drain here the reconnect channel and reconnect only once | ||
if d.needsReconnect() { | ||
log.Debug("dbusEventLoop: drained reconnect req channel") | ||
log.Trace("dbusEventLoop: daemon needs to reconnect") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reference point for message above. Only now one check for setting needsReconnect to True There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okey. But I think now the comment above with regards to "draining" the channel is obsolete, as with the current code this is the only point where the message loop can signal a re-connection. I think the code is good but we need to adjust the miss-leading comment (or remove?) |
||
needsReconnect = true | ||
} | ||
|
||
} | ||
// TODO: moving these assignments one scope up would make d.authorized redundant... | ||
d.serverJwt = token | ||
d.serverUrl = serverURL | ||
} | ||
} | ||
if needsReconnect && d.authorized { | ||
jwtToken, serverURL, _ := client.GetJWTToken() | ||
e := MenderShellDaemonEvent{ | ||
event: EventReconnect, | ||
data: jwtToken, | ||
id: "(dbusEventLoop)", | ||
|
||
if needsReconnect || d.needsReconnect() { | ||
log.Trace("dbusEventLoop: daemon needs to reconnect") | ||
_, err := client.FetchJWTToken() | ||
if err != nil { | ||
log.Errorf("dbusEventLoop: error fetching JWT token") | ||
} | ||
log.Tracef("(dbusEventLoop) posting Event: %s", e.event) | ||
d.serverUrl = serverURL | ||
d.serverJwt = jwtToken | ||
d.postEvent(e) | ||
needsReconnect = false | ||
} | ||
} | ||
|
||
log.Trace("dbusEventLoop: returning") | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this newest commit I removed this extra check "if d.needsReconnect" early in the function which set the needsReconnect value to True. Rather the code now only have one check. Having these two checks doing the same thing must have delayed the tests and made it fail.