Super Sale Limited Time 50% OFF for All-Access Plans
Save 50% Now

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
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • 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
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(