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


##########
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:
   I think even `AirflowException` is wrong (as it makes everything the same 
type) -- why can't we let the existing OSError etc exceptions be caught here? 
i.e. even using AirflowException here is wrong I think.
   
   With the addition of the `self._log_exc` you've added, wouldn't that be 
enough, and then letting the exception just bubble up might be enough?
   
   Or another option, is to add a note to it https://peps.python.org/pep-0678/ 
-- this works on Python 3.11+, which is now most of the versions. I think I 
prefer this (and on 3.10 the behaviour is just nothing else)
   
   So, on 3.10: log something about it, on 3.11 _don't_ log at site (else the 
exception stack gets logged twice, once there and once at the top level catch) 
and we use add_note to add information about what the cause was.



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