imbajin commented on code in PR #336:
URL: 
https://github.com/apache/incubator-hugegraph-computer/pull/336#discussion_r2422641675


##########
vermeer/apps/master/bl/scheduler_bl.go:
##########
@@ -202,6 +417,7 @@ func (s *ScheduleBl) startWaitingTask(agent 
*schedules.Agent, taskInfo *structur
                }
        }()
 
+       // TODO: Is here need a lock? TOCTTOU

Review Comment:
   **Race condition risk in task state checking**
   
   There's a TOCTTOU (Time-of-check to time-of-use) issue here. The comment 
indicates this concern but it should be addressed. Between checking the task 
state and starting the task, another goroutine could modify the state.
   
   **Suggested fix:**
   ```go
   // Acquire lock before checking and starting
   s.Lock()
   defer s.Unlock(nil)
   
   if taskInfo.State != structure.TaskStateWaiting {
       logrus.Errorf("task state is not in 'Waiting' state, taskID: %v", 
taskInfo)
       return
   }
   
   taskStarter, err := NewTaskStarter(taskInfo, agent)
   if err != nil {
       logrus.Errorf("failed to create new TaskStarter err: %v", err)
       taskMgr.SetError(taskInfo, err.Error())
       return
   }
   
   taskInfo.StartTime = time.Now()
   err = taskStarter.StartTask()
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to