THISisZOLI opened a new pull request, #25253: URL: https://github.com/apache/airflow/pull/25253
Starting Airflow components using the `--stdout` and `--stderr` arguments redirects the output streams to a log file. Currently the access type for these log files is `w+`. My problem with this access mode is that it can create sparse files. If the log file is moved or deleted, a new one will be created and the stdout/stderr will be written into it, but not from the start of the file. Instead if the original log file was x characters long, the new log file will contain x null bytes, and the new lines will be appended after that. To fix this problem we need to open the file with an access mode that has the `O_APPEND` flag enabled. Short list of access modes and flags: | fopen() mode | open() flags | | --- | --- | | w+ | O_RDWR \| O_CREAT \| O_TRUNC | | w | O_WRONLY \| O_CREAT \| O_TRUNC | | a | O_WRONLY \| O_CREAT \| O_APPEND | | a+ | O_RDWR \| O_CREAT \| O_APPEND | Based on this I propose changing the access mode for these output files from `w+` to `a`. I don't think there's any need to have read access so `+` can be dismissed. The problem with this solution is that the `a` mode does not have the `O_TRUNC` flag enabled, which means that the output file is not truncated when a component is restarted. To preserve this behaviour we can manually truncate the files with `handler.truncate(0)`. We could also set the flags manually for the handlers but I don't think that it will make the solution more readable. --- **^ Add meaningful description above** Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#pull-request-guidelines)** for more information. In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvements+Proposals)) is needed. In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x). In case of backwards incompatible changes please leave a note in a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [newsfragments](https://github.com/apache/airflow/tree/main/newsfragments). -- 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]
