Skip to content

fix: race condition where _template remains UNSET - #1588

Merged
JuroOravec merged 3 commits into
django-components:masterfrom
oliverhaas:fix/template-unset-race-condition
Feb 4, 2026
Merged

JuroOravec merged 3 commits into
django-components:masterfrom
oliverhaas:fix/template-unset-race-condition

Conversation

@oliverhaas

Copy link
Copy Markdown
Contributor

See #1587.

Basically the idea is here to change the order of the logic a little bit, so the idempotent loading might happen twice, but a race condition does not lead to an error.

Test is just for illustration. I would not merge the test.

Two fixes:
1. component_media.py: Retry loading if _template is still UNSET
2. template.py: Treat UNSET as None when reading _template
@github-actions

github-actions Bot commented Feb 4, 2026

Copy link
Copy Markdown
Contributor

Performance Benchmark Results

Comparing PR changes against master branch:

Benchmarks that have stayed the same:

Change Before [6f153ff] After [1be5923] Ratio Benchmark (Parameter)
68.3±0.8ms 69.3±0.6ms 1.01 Components vs Django.timeraw_render_lg_first('django')
246±2ms 246±3ms 1 Components vs Django.timeraw_render_lg_first('django-components')

@github-actions

github-actions Bot commented Feb 4, 2026

Copy link
Copy Markdown
Contributor

Performance Benchmark Results

Comparing PR changes against master branch:

Benchmarks that have stayed the same:

Change Before [63a05ad] After [1592cea] Ratio Benchmark (Parameter)
67.5±0.3ms 67.9±0.5ms 1.01 Components vs Django.timeraw_render_lg_first('django')
242±2ms 243±3ms 1 Components vs Django.timeraw_render_lg_first('django-components')

@JuroOravec

Copy link
Copy Markdown
Collaborator

@oliverhaas Thanks for looking into this and fixing it! The only Django project I worked on was single thread WSGI app, and I didn't work with multithreaded Python programs yet, so issues like this can fall through the cracks. So I appreciate your help.

I've fixed linter errors + bit of cleanup. The test does actually capture the error, so I think it's fine keeping it :)

@JuroOravec
JuroOravec merged commit 6446035 into django-components:master Feb 4, 2026
16 checks passed
@github-actions

github-actions Bot commented Feb 4, 2026

Copy link
Copy Markdown
Contributor

Performance Benchmark Results

Comparing PR changes against master branch:

Benchmarks that have stayed the same:

Change Before [63a05ad] After [1095631] Ratio Benchmark (Parameter)
60.4±1ms 62.4±1ms 1.03 Components vs Django.timeraw_render_lg_first('django')
218±4ms 225±5ms 1.03 Components vs Django.timeraw_render_lg_first('django-components')

@oliverhaas
oliverhaas deleted the fix/template-unset-race-condition branch February 5, 2026 03:55
@oliverhaas

Copy link
Copy Markdown
Contributor Author

The only Django project I worked on was single thread WSGI app, and I didn't work with multithreaded Python programs yet, so issues like this can fall through the cracks.

No worries.

I'm actually not happy about our production setup. Threading causes a couple annoying issues, but also without it we have other downsides.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants