ashb commented on code in PR #53958:
URL: https://github.com/apache/airflow/pull/53958#discussion_r2244995961


##########
airflow-core/src/airflow/exceptions.py:
##########
@@ -511,3 +511,35 @@ def __str__(self):
 
 class UnknownExecutorException(ValueError):
     """Raised when an attempt is made to load an executor which is not 
configured."""
+
+
+class AirflowFileLockAcquireException(AirflowException):
+    """Raised when a file lock cannot be acquired (e.g., via `fcntl.flock` 
with LOCK_SH or LOCK_EX)."""
+
+    def __init__(self, file_path: str | None, original_exception: Exception | 
None = None):
+        super().__init__()
+        self.file_path = file_path
+        self.original_exception = original_exception

Review Comment:
   We don't need to handle the original exception for us -- the `raise ... from 
e` means the original exception will already be recorded in `self.__cause__` 
(and displayed for us by pthon)



##########
airflow-core/src/airflow/dag_processing/bundles/base.py:
##########
@@ -428,12 +429,23 @@ def acquire(self):
         self._update_version_file()
         if TYPE_CHECKING:
             assert self.lock_file_path
+        # Raises FileNotFoundError if the path doesn't exist,
+        # or PermissionError if access is denied
         self.lock_file = open(self.lock_file_path)
-        flock(self.lock_file, LOCK_SH)
+        # https://docs.python.org/3/library/fcntl.html#fcntl.flock
+        try:
+            flock(self.lock_file, LOCK_SH)
+        except (BlockingIOError, OSError) as e:
+            self._log_exc("Error acquiring lock")
+            raise AirflowFileLockAcquireException(self.lock_file_path, e) from 
e

Review Comment:
   Do we really need these custom exceptions here? AirflowException isn't 
"special" in anyway, and in the past we (the project) have over used it, so I'm 
wondering if we need this at all?



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

Reply via email to