Get 2024 Templates Mega Bundle!$1000 worth of 19 Bootstrap HTML, Vue & React Templates + 3 Vector Sets for just $99
Get for 99$

Django's implementation with metronic has a race condition.


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


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (3)


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)

The `addVendors` function takes a list of vendors as a parameter (`vendors`). It iterates over each value in the `vendors` list. If the value is not already present in the `KTTheme.vendorFiles` list, it is appended to the list.

This function ensures that duplicate entries are skipped, preventing the addition of duplicate vendor files to the `KTTheme.vendorFiles` list.

This function appends new vendor files without replacing the original values. Therefore, the original value of the view 1 Vendor (datatables) should not be lost when adding the vendor for view 2.


Thanks



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


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(