You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "utkarsh39 (via GitHub)" <gi...@apache.org> on 2024/03/22 15:35:03 UTC

Re: [PR] [WIP] First stab at dealing with worker crashes while idling [spark]

utkarsh39 commented on code in PR #45635:
URL: https://github.com/apache/spark/pull/45635#discussion_r1535780432


##########
core/src/main/scala/org/apache/spark/api/python/PythonWorkerFactory.scala:
##########
@@ -95,10 +95,19 @@ private[spark] class PythonWorkerFactory(
   def create(): (PythonWorker, Option[Long]) = {
     if (useDaemon) {
       self.synchronized {
-        if (idleWorkers.nonEmpty) {
+        while (idleWorkers.nonEmpty) {
           val worker = idleWorkers.dequeue()
-          worker.selectionKey.interestOps(SelectionKey.OP_READ | SelectionKey.OP_WRITE)
-          return (worker, daemonWorkers.get(worker))
+          val workerHandle = daemonWorkers(worker)
+          try {
+            worker.selectionKey.interestOps(SelectionKey.OP_READ | SelectionKey.OP_WRITE)
+          } catch {
+            case c: CancelledKeyException => /* pass */
+          }
+          if (workerHandle.isAlive() && worker.selectionKey.isValid()) {

Review Comment:
   If the `interestOps` call succeed, will both of these checks be automatically true? 



##########
core/src/main/scala/org/apache/spark/api/python/PythonWorkerFactory.scala:
##########
@@ -95,10 +95,19 @@ private[spark] class PythonWorkerFactory(
   def create(): (PythonWorker, Option[Long]) = {
     if (useDaemon) {
       self.synchronized {
-        if (idleWorkers.nonEmpty) {
+        while (idleWorkers.nonEmpty) {
           val worker = idleWorkers.dequeue()
-          worker.selectionKey.interestOps(SelectionKey.OP_READ | SelectionKey.OP_WRITE)
-          return (worker, daemonWorkers.get(worker))
+          val workerHandle = daemonWorkers(worker)
+          try {
+            worker.selectionKey.interestOps(SelectionKey.OP_READ | SelectionKey.OP_WRITE)
+          } catch {
+            case c: CancelledKeyException => /* pass */
+          }
+          if (workerHandle.isAlive() && worker.selectionKey.isValid()) {
+            return (worker, Some(workerHandle.pid()))

Review Comment:
   Should we move this to the try block?



##########
python/pyspark/tests/test_worker.py:
##########
@@ -256,6 +257,20 @@ def conf(cls):
         return _conf
 
 
+class WorkerPoolCrashTest(PySparkTestCase):
+    def test_worker_crash(self):

Review Comment:
   Does this test fail today?



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org