Skip to content

Commit

Permalink
fix: panic in SerializePerf if context is cancelled
Browse files Browse the repository at this point in the history
Due to the changes in 541bc9f,
it is now possible for some of the serialize methods to return nil if
the context is cancelled. This can result in a nil reference panic in a
few cases if the caller isn't prepared for that case.
  • Loading branch information
adam-azarchs committed Aug 18, 2023
1 parent 61fafb1 commit 4ac3e34
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions martian/core/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,9 @@ func (self *Node) serializeState(ctx context.Context) *NodeInfo {
}
forks = append(forks, fork.serializeState(ctx))
}
if ctx.Err() != nil {
return nil
}
edges := make([]EdgeInfo, 0, len(self.directPrenodes))
for _, prenode := range self.directPrenodes {
if ctx.Err() != nil {
Expand Down Expand Up @@ -1056,6 +1059,9 @@ func (self *Node) serializePerf(ctx context.Context) (*NodePerfInfo, []*VdrEvent
return nil, nil
}
forkSer, vdrKill := fork.serializePerf(ctx)
if ctx.Err() != nil {
return nil, nil
}
forks = append(forks, forkSer)
if vdrKill != nil && self.call.Kind() != syntax.KindPipeline {
storageEvents = append(storageEvents, vdrKill.Events...)
Expand Down
3 changes: 3 additions & 0 deletions martian/core/pipestance.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,9 @@ func (self *Pipestance) SerializePerf(ctx context.Context) []*NodePerfInfo {
perf, _ := node.serializePerf(ctx)
ser = append(ser, perf)
}
if ctx.Err() != nil {
return nil
}
util.LogInfo("perform", "Serializing pipestance performance data.")
if len(ser) > 0 && ctx.Err() == nil {
overallPerf := ser[0]
Expand Down
4 changes: 4 additions & 0 deletions martian/core/stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -1575,6 +1575,10 @@ func (self *Fork) serializePerf(ctx context.Context) (*ForkPerfInfo, *VDRKillRep
return nil, nil
}
subforkSer, subforkKillReport := subfork.serializePerf(ctx)
if ctx.Err() != nil {
// If the context has expired, subforkSer will be nil.
return nil, nil
}
stats = append(stats, subforkSer.ForkStats)
if subforkKillReport != nil {
killReports = append(killReports, subforkKillReport)
Expand Down

0 comments on commit 4ac3e34

Please sign in to comment.