You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I updated the upload.sh file, which had a pipeline detection issue and got stuck in this loop
while [ ! -p ${UPLOAD_PIPE_FILE} ];
do
echo "Waiting for ${UPLOAD_PIPE_FILE} to be created"
sleep 1
done
Key Changes Made:
Added Timeout Mechanism: The script will exit if the pipe file is not detected within a specified timeout period.
Improved Logging: Added more detailed logging to help diagnose issues with the pipe file detection.
Check File Existence Before Pipe Check: Ensures the file exists before checking if it is a named pipe.
Motivation and Context
I submitted a bug report 3 weeks ago about this issue, and it seems that it wasn't fixed till now. I wanted to fix this issue as soon as possible as our testing process relied on uploading videos to an s3 bucket. I managed to isolate the issue rather quickly and managed to write a fix on my own.
Types of changes
Bug fix (non-breaking change which fixes an issue)
New feature (non-breaking change which adds functionality)
Breaking change (fix or feature that would cause existing functionality to change)
Possible Infinite Loop The loop starting at line 72 may potentially become an infinite loop if the named pipe is not created successfully within the timeout period, or if it continuously fails to be recognized as a named pipe. This could be due to external factors affecting file creation or deletion.
Resource Cleanup The script should ensure that resources (like created named pipes) are cleaned up properly in case of errors or when the script exits, to avoid leaving system resources in an inconsistent state.
Implement a mechanism to handle the scenario where the mkfifo command fails to create the pipe, such as logging an error message and exiting the script gracefully to avoid infinite loops or unhandled errors.
-mkfifo "${UPLOAD_PIPE_FILE}"-echo "Created named pipe ${UPLOAD_PIPE_FILE}"+if ! mkfifo "${UPLOAD_PIPE_FILE}"; then+ echo "Failed to create named pipe ${UPLOAD_PIPE_FILE}"+ exit 1+else+ echo "Created named pipe ${UPLOAD_PIPE_FILE}"+fi
Apply this suggestion
Suggestion importance[1-10]: 10
Why: This suggestion is crucial as it adds error handling for the mkfifo command, preventing the script from entering an infinite loop or failing silently, which significantly improves reliability.
10
Possible bug
Ensure SE_VIDEO_UPLOAD_BATCH_CHECK is defined and numeric before use
Add a check to ensure that the SE_VIDEO_UPLOAD_BATCH_CHECK variable is defined and is a numeric value before comparing it in the if condition to prevent script errors in case of undefined or non-numeric values.
Why: This suggestion adds a necessary check to prevent potential script errors due to undefined or non-numeric values, improving the robustness of the script.
9
Robustness
Add a maximum attempt limit to the named pipe creation loop to prevent potential infinite loops
To prevent potential infinite loops, add a mechanism to break out of the loop if the named pipe is not successfully created within a reasonable number of attempts, instead of relying solely on the timeout.
+MAX_ATTEMPTS=5+attempt_count=0
while true; do
+ if (( attempt_count++ >= MAX_ATTEMPTS )); then+ echo "Maximum attempts reached, unable to create named pipe"+ exit 1+ fi
...
sleep 1
done
Suggestion importance[1-10]: 8
Why: This suggestion adds an additional layer of robustness by ensuring the script does not enter an infinite loop, complementing the existing timeout mechanism.
8
Performance
Optimize the loop for checking and creating the named pipe to avoid busy waiting
Instead of using a while loop to continuously check and create the named pipe, consider using a more efficient approach by leveraging a timeout mechanism directly in the mkfifo command if supported, or by using a single loop with a sleep delay to avoid busy waiting.
-while true; do- if [ -e "${UPLOAD_PIPE_FILE}" ];- then- if [ -p "${UPLOAD_PIPE_FILE}" ];- then- break- else- echo "${UPLOAD_PIPE_FILE} exists but is not a named pipe"- create_named_pipe- fi- else- create_named_pipe+if [ ! -p "${UPLOAD_PIPE_FILE}" ]; then+ if [ -e "${UPLOAD_PIPE_FILE}" ]; then+ echo "${UPLOAD_PIPE_FILE} exists but is not a named pipe"+ rm -f "${UPLOAD_PIPE_FILE}"
fi
- ...- sleep 1-done+ mkfifo "${UPLOAD_PIPE_FILE}"+ echo "Created named pipe ${UPLOAD_PIPE_FILE}"+fi
Suggestion importance[1-10]: 7
Why: The suggestion improves performance by reducing busy waiting, but it removes the timeout mechanism which is crucial for handling cases where the pipe is not created within a reasonable time.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User description
Fixing video upload pipeline detection
Description
Fixes #2318
Issues found:
I updated the upload.sh file, which had a pipeline detection issue and got stuck in this loop
Key Changes Made:
Motivation and Context
I submitted a bug report 3 weeks ago about this issue, and it seems that it wasn't fixed till now. I wanted to fix this issue as soon as possible as our testing process relied on uploading videos to an s3 bucket. I managed to isolate the issue rather quickly and managed to write a fix on my own.
Types of changes
Checklist
PR Type
Bug fix
Description
Changes walkthrough 📝
upload.sh
Enhance upload script with timeout and improved pipe detection
Video/upload.sh
within a specified period.