Skip to content

Conversation

@sergio-nsk
Copy link
Collaborator

No description provided.

@sergio-nsk sergio-nsk added the bug Something isn't working label Jan 17, 2026
@codecov-commenter
Copy link

codecov-commenter commented Jan 17, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.64%. Comparing base (18d4beb) to head (90240c2).

Files with missing lines Patch % Lines
threadpool_pthread.c 50.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #122      +/-   ##
==========================================
- Coverage   58.70%   58.64%   -0.06%     
==========================================
  Files          32       32              
  Lines        2603     2607       +4     
  Branches      524      526       +2     
==========================================
+ Hits         1528     1529       +1     
- Misses        741      743       +2     
- Partials      334      335       +1     
Flag Coverage Δ
macos 55.15% <50.00%> (-0.05%) ⬇️
macos_duktape 60.04% <50.00%> (-0.07%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request fixes a bug where the minimum thread count (min_threads) was being ignored in the POSIX threadpool implementation. The fix ensures that when jobs are enqueued, the threadpool creates threads up to the configured minimum if fewer threads currently exist.

Changes:

  • Modified threadpool_create_thread_on_demand to return a boolean indicating success/failure instead of void
  • Added logic in threadpool_enqueue to create threads up to min_threads before processing jobs

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 171 to +177
threadpool_thread_s *thread = (threadpool_thread_s *)calloc(1, sizeof(threadpool_thread_s));
thread->handle = handle;
thread->next = threadpool->threads;

threadpool->threads = thread;
threadpool->num_threads++;
return true;
Copy link

Copilot AI Jan 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function creates a pthread but doesn't check if the subsequent calloc fails. If calloc fails (thread is NULL), the code will dereference a NULL pointer on line 172. Additionally, if calloc fails after pthread_create succeeds, the created thread will be orphaned (memory leak) since the thread handle is not stored and cannot be joined later. Add a NULL check after calloc and if it fails, consider detaching the thread or implementing proper cleanup.

Copilot uses AI. Check for mistakes.
Comment on lines 200 to 201
if (threadpool->busy_threads == threadpool->num_threads && threadpool->num_threads < threadpool->max_threads)
threadpool_create_thread_on_demand(threadpool);
Copy link

Copilot AI Jan 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return value of threadpool_create_thread_on_demand is ignored here. If thread creation fails at this point (when all threads are busy), the failure will be silent and the job may not be processed in a timely manner. Consider checking the return value and possibly logging a warning when thread creation fails.

Suggested change
if (threadpool->busy_threads == threadpool->num_threads && threadpool->num_threads < threadpool->max_threads)
threadpool_create_thread_on_demand(threadpool);
if (threadpool->busy_threads == threadpool->num_threads && threadpool->num_threads < threadpool->max_threads) {
if (!threadpool_create_thread_on_demand(threadpool)) {
fprintf(stderr, "threadpool: warning: failed to create thread on demand; job processing may be delayed\n");
}
}

Copilot uses AI. Check for mistakes.
Comment on lines +193 to +197
// Create min amount of threads
while (threadpool->num_threads < threadpool->min_threads) {
if (!threadpool_create_thread_on_demand(threadpool))
break;
}
Copy link

Copilot AI Jan 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new functionality to ensure minimum threads are created lacks test coverage. Consider adding a test that verifies min_threads are actually created when jobs are enqueued, especially to prevent regression of this bug in the future.

Copilot uses AI. Check for mistakes.
@sergio-nsk sergio-nsk merged commit a032b7b into master Jan 17, 2026
38 of 39 checks passed
@sergio-nsk sergio-nsk deleted the sergio-nsk/thread/2 branch January 17, 2026 01:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants