php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #59876 memcache uses select() please provide fallback
Submitted: 2011-07-31 07:57 UTC Modified: -
Votes:6
Avg. Score:4.5 ± 0.5
Reproduced:5 of 5 (100.0%)
Same Version:2 (40.0%)
Same OS:4 (80.0%)
From: debian at toell dot net Assigned:
Status: Open Package: memcache (PECL)
PHP Version: 5.3.6 OS: Debian (all flavors)
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2011-07-31 07:57 UTC] debian at toell dot net
Description:
------------
On behalf of a Debian user reporting this problem to the Debian bug tracker in http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=629896 I'm reporting the very same issue to your bug tracker.


When using the memcache extension on a heavy loaded server it is possible the available file descriptors are exhausted causing memcache to crash. This is by design of the select(2) syscall which has a word limit of typcially 1024 file descriptors in its FD_SET 

From the man page:

An fd_set is a fixed size buffer.  Executing FD_CLR() or FD_SET() with a value of fd that is negative or is equal to  or  larger  than  FD_SETSIZE will result in undefined behavior.  Moreover, POSIX requires fd to be a valid file descriptor.


memcache uses select() in memcache_pool.c line 1434 of todays trunk. Excerpt of a strace from the original Debian bug report:

sendto(3146, "get test-strix-joy-zg_news_1_new"..., 55, MSG_NOSIGNAL, NULL, 0) = 55
select(3147, [1024 1219 1221 1222 1224 1227 1230 1231 1235 1241 1242 1243 1244 1245 1252 1255 1256 1257 1258 1259 1260 1261 1262 1283 1284 1287 1288 1291 1294 1295 1299 1305 1306 1307 1308 1309 1316 1319 1320 1321 1322 1323 1324 1325 1326 1347 1348 1350 1352 1353 1354 1355 1356 1357 1358 1360 1363 1364 1365 1369 1370 1371 1372 1373 1380 1383 1384 1385 1386 1387 1388 1389 1390 1409 1411 1412 1731 1732 1734 1737 1738 1739 1740 1741 1742 1744 1747 1748 1749 1753 1754 1755 1756 1757 1764 1767 1768 1769 1770 1771 1772 1773 1774 1793 1795 1796 1924 1925 1927 1928 1930 1933 1934 1935 1936 1939 1940 1942 1945 1946 1947 1948 1949 1956 1959 1960 1961 1962 1963 1964 1965 1966 1985 1987 1988 2080 2497 2499 2500 2503 2504 2507 2508 2511 2512 2515 2516 2519 2520 2523 2524 2527 2528 2531 2532 2535 2536 2539 2540 2543 2544 2547 2550 2551 2552 2553 2554 2555 2556 2557 2565 2569 2570 2571 2574 2630 2631 2632 2633 2635 2636 2640 2643 2646 2651 2653 2660 2663 2664 2665 2666 2667 2668 2669 2670 2752 2753 2756 2757 2765 2768 2772 2777 2778 2779 2780 2783 2784 2785 2786 2787 2788 2789 2790 2791 2794 2797 2799 2800 2802 2803 2806 2808 2809 2811 2812 2817 2818 2827 2828 2829 2834 2835 2837 2838 2839 2841 2842 2844 2846 2849 2850 2852 2853 2856 2859 2860 2862 2863 2864 2866 2867 2870 2871 2872 2873 2874 2879 2880 2884 2886 2944 2948 2949 2953 3013 3073 3074 3075 3078 3080 3081 3082 3083 3085 3088 3089 3090 3091 3095 3099 3101 3104 3105 3107 3110 3115 3121 3122 3124 3126 3127 3129 3133 3134 3135 3139 3145 3146], [2048 2243 2245 2246 2248 2251 2254 2255 2259 2265 2266 2267 2268 2269 2276 2279 2280 2281 2282 2283 2284 2285 2286 2307 2308 2311 2312 2315 2318 2319 2323 2329 2330 2331 2332 2333 2340 2343 2344 2345 2346 2347 2348 2349 2350 2371 2372 2374 2376 2377 2378 2379 2380 2381 2382 2384 2387 2388 2389 2393 2394 2395 2396 2397 2404 2407 2408 2409 2410 2411 2412 2413 2414 2433 2435 2436 2755 2756 2758 2761 2762 2763 2764 2765 2766 2768 2771 2772 2773 2777 2778 2779 2780 2781 2788 2791 2792 2793 2794 2795 2796 2797 2798 2817 2819 2820 2948 2949 2951 2952 2954 2957 2958 2959 2960 2963 2964 2966 2969 2970 2971 2972 2973 2980 2983 2984 2985 2986 2987 2988 2989 2990 3009 3011 3012 3104], NULL, {1, 0}) = 435 (in [1024 1219 1221 1222 1224 1227 1230 1231 1235 1241 1242 1243 1244 1245 1252 1255 1256 1257 1258 1259 1260 1261 1262 1283 1284 1287 1288 1291 1294 1295 1299 1305 1306 1307 1308 1309 1316 1319 1320 1321 1322 1323 1324 1325 1326 1347 1348 1350 1352 1353 1354 1355 1356 1357 1358 1360 1363 1364 1365 1369 1370 1371 1372 1373 1380 1383 1384 1385 1386 1387 1388 1389 1390 1409 1411 1412 1731 1732 1734 1737 1738 1739 1740 1741 1742 1744 1747 1748 1749 1753 1754 1755 1756 1757 1764 1767 1768 1769 1770 1771 1772 1773 1774 1793 1795 1796 1924 1925 1927 1928 1930 1933 1934 1935 1936 1939 1940 1942 1945 1946 1947 1948 1949 1956 1959 1960 1961 1962 1963 1964 1965 1966 1985 1987 1988 2080 2497 2499 2500 2503 2504 2507 2508 2511 2512 2515 2516 2519 2520 2523 2524 2527 2528 2531 2532 2535 2536 2539 2540 2543 2544 2547 2550 2551 2552 2553 2554 2555 2556 2557 2565 2569 2570 2571 2574 2630 2631 2632 2633 2635 2636 2640 2643 2646 2651 2653 2660 2663 2664 2665 2666 2667 2668 2669 2670 2752 2753 2756 2757 2765 2768 2772 2777 2778]])
recvfrom(3146, "END\r\n", 32768, 0, NULL, NULL) = 5
--- SIGSEGV (Segmentation fault) @ 0 (0) ---


Please provide a fallback method for heavy loaded servers, by using any other polling mechanism or replace select() completely. Depending how much you care about portability one [e]poll() variant or even libev. 


Patches

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Thu Oct 17 20:01:28 2019 UTC