Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some major improvements in FaceRec/app/main/Edit.py #73

Open
bhavya2021245 opened this issue Oct 10, 2024 · 4 comments · May be fixed by #86
Open

some major improvements in FaceRec/app/main/Edit.py #73

bhavya2021245 opened this issue Oct 10, 2024 · 4 comments · May be fixed by #86

Comments

@bhavya2021245
Copy link

Describe the bug
The Flask application exhibits several critical issues that impact its reliability, security, and maintainability:

1.Improper Resource Management for Video Capture:
The camera resource (cv2.VideoCapture(0)) is initialized at the module level and is never released. This leads to the camera remaining occupied even after the application stops, preventing other applications or subsequent runs from accessing the camera.

2.Lack of Comprehensive Error Handling and Input Validation:
The application does not adequately validate user inputs, allowing invalid or malicious data to be processed. Additionally, exceptions during camera access, file operations, or HTTP requests are not gracefully handled, potentially causing the application to crash or behave unpredictably.

3.Use of Global Variables Leading to Potential Race Conditions:
Global variables (EmployeeCode, Name, gender, Dept, encoded_image) are used to store temporary data across different routes. This practice can lead to race conditions in a multi-threaded environment, making the application unreliable and difficult to maintain.

To Reproduce
Steps to reproduce the issues:

1.Improper Resource Management:
Start the Flask application.
Access the video feed via the /video_feed route.
Stop the Flask application without properly releasing the camera resource.
Attempt to restart the Flask application or use the camera in another application.
Observe that the camera cannot be accessed due to it being locked by the previous instance.

2.Lack of Comprehensive Error Handling and Input Validation:
Start the Flask application.
Navigate to the /capture route.
Submit the form with invalid data (e.g., non-numeric EmployeeCode, empty fields).
Observe that the application may crash or behave unpredictably without providing meaningful error messages.

3.Use of Global Variables Leading to Potential Race Conditions:
Start the Flask application.
Simultaneously make multiple requests to the /capture route from different clients or browser tabs.
Observe that global variables may be overwritten or accessed inconsistently, leading to incorrect data being processed or displayed.

Expected behavior
The application should exhibit the following behaviors to address the identified issues:

1.Proper Resource Management for Video Capture:
The camera resource should be initialized in a thread-safe manner and properly released when no longer needed or when the application stops. This ensures that other applications or subsequent runs can access the camera without issues.

2.Enhanced Error Handling and Input Validation:
All user inputs should be validated to ensure they meet required formats and constraints. The application should handle exceptions gracefully by catching errors and providing informative feedback to the user without crashing.

3.Refactoring to Avoid Global Variables and Improve Code Structure:
Temporary data should be stored within the scope of individual requests using mechanisms like Flask’s g object instead of global variables. This prevents race conditions and ensures data integrity across concurrent requests. Additionally, the code should be modularized to enhance readability and maintainability.

@bhavya2021245
Copy link
Author

Please assign me this issue under hacktoberfest-accepted and gssoc-ext

@devansh-shah-11
Copy link
Collaborator

sure - go ahead

@bhavya2021245
Copy link
Author

You have assigned this issue to me right??

@Devasy23
Copy link
Owner

yes @bhavya2021245

You have assigned this issue to me right??

@Devasy23 Devasy23 linked a pull request Oct 13, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants