github-advanced-security[bot] commented on code in PR #18851:
URL: https://github.com/apache/druid/pull/18851#discussion_r2762617243


##########
indexing-service/src/main/java/org/apache/druid/indexing/overlord/hrtr/HttpRemoteTaskRunner.java:
##########
@@ -1139,37 +1098,38 @@
   @Override
   public ListenableFuture<TaskStatus> run(Task task)
   {
-    Preconditions.checkState(lifecycleLock.awaitStarted(1, 
TimeUnit.MILLISECONDS), "not started");
+    Preconditions.checkState(lifecycleLock.awaitStarted(1, 
TimeUnit.MILLISECONDS), "TaskRunner not started.");
 
-    synchronized (statusLock) {
-      HttpRemoteTaskRunnerWorkItem existing = tasks.get(task.getId());
+    AtomicReference<ListenableFuture<TaskStatus>> taskFuture = new 
AtomicReference<>();
 
-      if (existing != null) {
-        log.info("Assigned a task[%s] that is known already. Ignored.", 
task.getId());
-        if (existing.getTask() == null) {
-          // in case it was discovered from a worker on start() and 
TaskAnnouncement does not have Task instance
-          // in it.
-          existing.setTask(task);
-        }
-        return existing.getResult();
-      } else {
-        log.info("Adding pending task[%s].", task.getId());
-        HttpRemoteTaskRunnerWorkItem taskRunnerWorkItem = new 
HttpRemoteTaskRunnerWorkItem(
-            task.getId(),
-            null,
-            null,
-            task,
-            task.getType(),
-            HttpRemoteTaskRunnerWorkItem.State.PENDING
-        );
-        tasks.put(task.getId(), taskRunnerWorkItem);
-        pendingTaskIds.add(task.getId());
+    log.info("Adding task[%s]", task.getId());
 
-        statusLock.notifyAll();
+    tasks.compute(
+        task.getId(), (id, entry) -> {
+          // Task already exists, but in case it was discovered from a worker 
on start()
+          // and TaskAnnouncement does not have Task instance, add it.
+          if (entry != null) {
+            if (entry.getTask() == null) {
+              entry.setTask(task);
+            }
+          } else {
+            entry = new HttpRemoteTaskRunnerWorkItem(
+                task.getId(),
+                null,
+                null,
+                task,
+                task.getType(),
+                HttpRemoteTaskRunnerWorkItem.State.PENDING
+            );
+            pendingTasks.offer(new PendingTaskQueueItem(task));

Review Comment:
   ## Ignored error status of call
   
   Method apply ignores exceptional return value of 
LinkedBlockingQueue<PendingTaskQueueItem>.offer.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/10802)



-- 
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