With my development team we bought the metronic template and after configuring and doing some tests, we found out that it has a race condition problem. We created a test with two simple views (similar to the example that the template brings in), in view number 1 we added a sleep function with 10 seconds, where a Vendor (datatables) has been added, the second view has no sleep function and also has a Vendor (bootstrap-select).We called the view 1 and then the view 2, to the end of the test, the view 1 has the value of Vendor (bootstrap-select) of view 2, the original value of the view 1 Vendor (datatables) is lost.
Classes used to recreate the issue:
.....
class HomeView(TemplateView):
# Default template file
template_name = 'pages/users/basic_example.html'
# Predefined function
def get_context_data(self, **kwargs):
# Call the base implementation first to get a context
context = super().get_context_data(**kwargs)
# A function to init the global layout. It is defined in _keenthemes/__init__.py file
context = KTLayout.init(context)
# Example Include vendors and javascript
KTTheme.addVendors(['datatables',])
time.sleep(10)
return context
class HomeView2(TemplateView):
# Default template file
template_name = 'pages/users/basic_example.html'
# Predefined function
def get_context_data(self, **kwargs):
# Call the base implementation first to get a context
context = super().get_context_data(**kwargs)
# A function to init the global layout. It is defined in _keenthemes/__init__.py file
context = KTLayout.init(context)
# Example Include vendors and javascript
KTTheme.addVendors(['bootstrap-select', ])
return context
Thank you for bringing this to our attention. We assure you that we will investigate and implement a fix to address this race condition.
We will implement a fix in the KTTheme class to ensure that concurrent modifications to the vendorFiles attribute do not interfere with each other. By implementing proper synchronization mechanisms, such as locks or thread-safe data structures, we can ensure that modifications are applied consistently and prevent the race condition from occurring.
We appreciate your patience, and we will work on resolving this issue. If you have any further questions or concerns, please feel free to let us know.
Best regards,
Hi,
May I know which Metronic version are you using?
This function is responsible for adding vendors to the `KTTheme.vendorFiles` list.
Here's an overview of the code (starterkit/_keenthemes/libs/theme.py):
def addVendors(vendors):
for value in vendors:
# Skip duplicate entry
if value not in KTTheme.vendorFiles:
KTTheme.vendorFiles.append(value)
Hi,
We are with version 8.1.8 of Metronic, on the other hand, as I mentioned, when carrying out tests, we observe that the original value of the Vendor (datatables) of view 1 is lost, instead of the Vendor (datatables) the Vendor (bootstrap-select) is rendered.
We believe that since the KTTheme class is unique and static, if there is a heavy process (like the one represented in the sleep function of view 1) and there is another request that right in the associated view modifies the vendorFiles attribute (like the one in the view 2), the race condition that we detected could occur.
We will carry out more tests and soon we will be reporting the results
Thansk