-
Notifications
You must be signed in to change notification settings - Fork 65
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
[MM-54157] Fix potential nil access upon starting a recording #495
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,11 @@ func (p *Plugin) recJobTimeoutChecker(callID, jobID string) { | |
// If the recording hasn't started (bot hasn't joined yet) we notify the | ||
// client. | ||
if recState.StartAt == 0 { | ||
if recState.JobID != jobID { | ||
p.LogInfo("a new job has started in between, exiting", "callID", callID, "jobID", jobID) | ||
return | ||
} | ||
|
||
p.LogError("timed out waiting for recorder bot to join", "callID", callID, "jobID", jobID) | ||
|
||
state.Call.Recording = nil | ||
|
@@ -78,7 +83,7 @@ func (p *Plugin) handleRecordingStartAction(state *channelState, callID, userID | |
|
||
defer func() { | ||
// In case of any error we relay it to the client. | ||
if res.Err != "" { | ||
if res.Err != "" && recState != nil { | ||
recState.EndAt = time.Now().UnixMilli() | ||
recState.Err = res.Err | ||
p.publishWebSocketEvent(wsEventCallRecordingState, map[string]interface{}{ | ||
|
@@ -113,6 +118,7 @@ func (p *Plugin) handleRecordingStartAction(state *channelState, callID, userID | |
res.Code = http.StatusInternalServerError | ||
return nil, res | ||
} | ||
|
||
if jobErr != nil { | ||
state.Call.Recording = nil | ||
if err := p.kvSetChannelState(callID, state); err != nil { | ||
|
@@ -185,29 +191,23 @@ func (p *Plugin) handleRecordingStopAction(state *channelState, callID string) ( | |
} | ||
}() | ||
|
||
// Sending the event prior to making the API call to the job service | ||
// since it could take a few seconds to complete but we want clients | ||
// to get their local state updated as soon as it changes on the server. | ||
p.publishWebSocketEvent(wsEventCallRecordingState, map[string]interface{}{ | ||
"callID": callID, | ||
"recState": recState.getClientState().toMap(), | ||
}, &model.WebsocketBroadcast{ChannelId: callID, ReliableClusterSend: true}) | ||
|
||
// We don't want to keep the lock while making the API call to the service since it | ||
// could take a while to return. | ||
p.unlockCall(callID) | ||
Comment on lines
-188
to
-198
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. Unrelated to the panic but since we moved to the new job API we don't need to do this, the stop action is completely asynchronous and safe to be called under lock. |
||
if err := p.getJobService().StopJob(callID); err != nil { | ||
res.Err = "failed to stop recording job: " + err.Error() | ||
res.Code = http.StatusInternalServerError | ||
return nil, res | ||
} | ||
|
||
p.publishWebSocketEvent(wsEventCallRecordingState, map[string]interface{}{ | ||
"callID": callID, | ||
"recState": recState.getClientState().toMap(), | ||
}, &model.WebsocketBroadcast{ChannelId: callID, ReliableClusterSend: true}) | ||
|
||
return recState.getClientState(), res | ||
} | ||
|
||
func (p *Plugin) handleRecordingAction(w http.ResponseWriter, r *http.Request, callID, action string) { | ||
var res httpResponse | ||
defer p.httpAudit("handlePostRecording", &res, w, r) | ||
defer p.httpAudit("handleRecordingAction", &res, w, r) | ||
|
||
userID := r.Header.Get("Mattermost-User-Id") | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Adding an extra check to avoid making potentially inconsistent state updates due to previously failed jobs. Ideally we'd cancel this timeout check whenever we stop a recording but the synchronization needed would make the code more complex so it seems like a few extra goroutines that return early are not too bad.