Bug 54311 - The return error is never checked for inappropriate ThreadStackSize
Summary: The return error is never checked for inappropriate ThreadStackSize
Status: RESOLVED FIXED
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: mpm_event (show other bugs)
Version: 2.4.3
Hardware: PC Linux
: P1 major (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
URL:
Keywords: FixedInTrunk, PatchAvailable
Depends on:
Blocks:
 
Reported: 2012-12-16 03:08 UTC by Tianyin Xu
Modified: 2013-05-12 10:40 UTC (History)
1 user (show)



Attachments
patch to check the return value and print the error setting (1.65 KB, patch)
2012-12-16 03:08 UTC, Tianyin Xu
Details | Diff
patch to check the return value and print the error setting (1.66 KB, patch)
2012-12-16 03:37 UTC, Tianyin Xu
Details | Diff
Please refer to this patch, thanks! (1.66 KB, patch)
2012-12-16 03:43 UTC, Tianyin Xu
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tianyin Xu 2012-12-16 03:08:11 UTC
Created attachment 29768 [details]
patch to check the return value and print the error setting

Hi, 

In both mpm_event and mpm_worker, the error return of inappropriate ThreadStackSize setting is not checked and printed out. This brings difficult to users who wants to set small ThreadStackSize. In my case, I cannot easily know whether the my setting is accepted or not without any log message.

The code is shown as follows:
/*
   server/mpm/event/event.c
   server/mpm/worker/worker.c
*/
if (ap_thread_stacksize != 0) {
    apr_threadattr_stacksize_set(thread_attr, ap_thread_stacksize);
}

The return value of apr_threadattr_stacksize_set() tells whether the setting is valid or not. But the current code does not check the return value.

I suggest to add a patch to check the return value and print out an error message, as follows (the patch is tested).

     if (ap_thread_stacksize != 0) {
-        rv = apr_threadattr_stacksize_set(thread_attr, ap_thread_stacksize);
-        if(rv != APR_SUCCESS) {
-            ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL, APLOGNO(00522)
-                         "WARNING: ThreadStackSize of %ld is inappropriate, change back to the default", 
-                         ap_thread_stacksize);
-        }
+        apr_threadattr_stacksize_set(thread_attr, ap_thread_stacksize);
     }   

The only thing I'm not sure is the APLOGNO. I don't know the rule of the number assignment. And it seems that adding a log message will break the sequential APLOGNO series.
Comment 1 Tianyin Xu 2012-12-16 03:37:58 UTC
Created attachment 29769 [details]
patch to check the return value and print the error setting

I update my patch. Thanks!
Comment 2 Tianyin Xu 2012-12-16 03:43:16 UTC
Created attachment 29770 [details]
Please refer to this patch, thanks!

Here is the correct one. I write it based on the SendBufferSize checker.

The old patches are obsolete because it does not consider return value could be APR_ENOTIMPL. Please refer to this one.

Thanks a lot!

-        apr_threadattr_stacksize_set(thread_attr, ap_thread_stacksize);
+        rv = apr_threadattr_stacksize_set(thread_attr, ap_thread_stacksize);
+        if(rv != APR_SUCCESS && rv != APR_ENOTIMPL) {
+            ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL, APLOGNO(00522)
+                         "WARNING: ThreadStackSize of %ld is inappropriate, using default", 
+                         ap_thread_stacksize);
+        }
Comment 3 Christophe JAILLET 2013-01-07 22:10:51 UTC
Thanks for the patch.

Looks reasonable.

Another place where the return value of 'apr_threadattr_stacksize_set' is not checked can be found on trunk in 'server/mpm/eventopt/eventopt.c' at line 2225
Comment 4 Tianyin Xu 2013-01-07 23:13:47 UTC
Thanks a lot, Christophe.

But I don't find the file, i.e., 'server/mpm/eventopt/eventopt.c' in my source directory (actually I even don't have the eventopt directory). 

Is it new in trunk (compared with my stable version)?
Comment 5 Christophe JAILLET 2013-01-15 21:55:00 UTC
Applied a slightly modified version to trunk.
r1433682

If nobody complains, I'll propose it for backport in 2.4.x branch.
Comment 6 Graham Leggett 2013-04-30 15:01:27 UTC
Proposed for backport to v2.4.
Comment 7 Graham Leggett 2013-05-12 10:40:06 UTC
Backported to v2.4.5.