Skip to content

Commit d0f44ac

Browse files
anim001keljobe
andauthored
Hardening: fix CloseExec race, secure chunk-size tests, enforce gci (#3747)
* Update validation_api.go * Update validation_api.go --------- Co-authored-by: Pepper Lebeck-Jobe <[email protected]>
1 parent 1453249 commit d0f44ac

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

validator/valnode/validation_api.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,16 @@ func (a *ExecServerAPI) CheckAlive(ctx context.Context, execid uint64) error {
212212
}
213213

214214
func (a *ExecServerAPI) CloseExec(execid uint64) {
215-
run, err := a.getRun(execid)
216-
if err != nil {
217-
return // means not found
215+
// Protect map access with runIdLock to avoid concurrent map read/write.
216+
// Call Close() outside the lock to avoid holding the mutex during a potentially long operation.
217+
a.runIdLock.Lock()
218+
entry := a.runs[execid]
219+
if entry != nil {
220+
delete(a.runs, execid)
221+
}
222+
a.runIdLock.Unlock()
223+
224+
if entry != nil {
225+
entry.run.Close()
218226
}
219-
run.Close()
220-
delete(a.runs, execid)
221227
}

0 commit comments

Comments
 (0)