<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugzilla.yoctoproject.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugzilla.yoctoproject.org/"
          
          maintainer="it-coreprojects-helpdesk@linuxfoundation.org"
>

    <bug>
          <bug_id>11309</bug_id>
          
          <creation_ts>2017-04-07 15:12:51 +0000</creation_ts>
          <short_desc>Pseudo locks up with high numbers of threads</short_desc>
          <delta_ts>2018-03-08 08:14:38 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>6</classification_id>
          <classification>Yocto Project Subprojects</classification>
          <product>Pseudo</product>
          <component>pseudo</component>
          <version>master</version>
          <rep_platform>x86</rep_platform>
          <op_sys>Multiple</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>Medium</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>2.5</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Richard Purdie">richard.purdie</reporter>
          <assigned_to name="Seebs">seebs</assigned_to>
          <cc>alex.kanavin</cc>
    
    <cc>anibal.limon</cc>
    
    <cc>juro.bystricky</cc>
    
    <cc>randy.macleod</cc>
    
    <cc>ross.burton</cc>
    
    <cc>yp.pseudo.watcher</cc>
    
    <cc>yp.watcher</cc>
          
          
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>No (bug/feature does not impact docs)</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>72178</commentid>
    <comment_count>0</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2017-04-07 15:12:51 +0000</bug_when>
    <thetext>I have some slightly crazy code which parallelises do_package_write_ipk and do_package_write_deb. I&apos;m running this on an 88 core system so BB_NUMBER_THREADS is 2*88.

When building linux-yocto or glibc-locale, we can end up executing dpkg-deb and opkg-build 2*88 instances all connecting to the same pseudo server. Sometimes this just sits there. Whether this is sensible or not, there probably is a bug hiding somewhere in here.

Attaching strace to the pseudo server process shows:

accept(5, 0x7fffbe37a7e0, 0x7fffbe37a714) = -1 EMFILE (Too many open files)
select(1024, [5 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023], [], [5 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023], {2, 0}) = 1 (in [5], left {1, 999908})
accept(5, 0x7fffbe37a7e0, 0x7fffbe37a714) = -1 EMFILE (Too many open files)

which just loops. It would be nice if we could find some way for pseudo to handle this more gracefully other than sitting using 100% cpu.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>72179</commentid>
    <comment_count>1</comment_count>
    <who name="Mark Hatle">mark.hatle</who>
    <bug_when>2017-04-07 15:19:57 +0000</bug_when>
    <thetext>On my own system w/ 144 threads, I&apos;ve had to bump the system and user limits.  I found that the stock 1024 files and such were simply not enough for these large builds.

My guess is that pseudo is causing a regular situation of &apos;1&apos; open file to suddenly become &apos;2&apos; or even &apos;3&apos;, effectively causing you to go over the max open files for your user.

Check the ulimit, and adjust the number -- if this resolves it, we at least have a temporary workaround until pseudo itself can more gracefully handle this issue.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>72533</commentid>
    <comment_count>2</comment_count>
    <who name="Seebs">seebs</who>
    <bug_when>2017-04-17 15:40:28 +0000</bug_when>
    <thetext>It may be possible to address this by arbitrarily closing one or more old client ports; the client should recover, as long as there was nothing being written to the port precisely at the time. (We can use only clients which are currently empty.) Since a client which is waiting to be accepted won&apos;t have a live connection, closing an existing connection arbitrarily will allow accepting a new connection and guarantee the ability to process messages from it, as long as we don&apos;t close the new connection soon. So we might need a LIFO client list or something.

The underlying problem is that you can have enough clients at once that the daemon can&apos;t open more sockets, because of the per-process open file limit. I am not sure there&apos;s a good way to solve this short of not running that many things.

Thinking about it, pseudo daemons are per-package, I believe, so for us to be seeing this, we&apos;d have to have ~1k processes *for one specific package* and that seems excessive. Or something else is going on.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>73844</commentid>
    <comment_count>3</comment_count>
    <who name="Seebs">seebs</who>
    <bug_when>2017-06-07 22:09:24 +0000</bug_when>
    <thetext>So, I&apos;ve been pondering this on and off, and basically: We can&apos;t reliably fix this without data loss without dropping the FASTOP feature. We can only safely disconnect clients if clients are guaranteed to notice that they got hung up on, which they currently aren&apos;t. I don&apos;t have hard numbers on the performance difference there, but it was noticeable.

I honestly think the best choice may just be to run with much higher openfiles, although I&apos;m still a bit confused by what&apos;s actually happening here; are we really ending up with ~1k distinct processes talking to the same pseudo server?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>73946</commentid>
    <comment_count>4</comment_count>
    <who name="Juro Bystricky">juro.bystricky</who>
    <bug_when>2017-06-09 15:23:38 +0000</bug_when>
    <thetext>The issue may have something to do with the fact that pseudo uses FD_SET &amp; friends. These operate on a bitfield of 1024 bits, and AFAIK there is no error check for boundries. So in principle the consequences would be that some innocent unreleated  memory locations will get a bit set or cleared.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>74657</commentid>
    <comment_count>5</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2017-06-29 19:40:51 +0000</bug_when>
    <thetext>RP has pushed:
commit f3589f154dad1c92e599737623d392508810ae7e
Author:     Richard Purdie &lt;richard.purdie@linuxfoundation.org&gt;
AuthorDate: Tue Apr 25 15:25:54 2017 +0100
Commit:     Richard Purdie &lt;richard.purdie@linuxfoundation.org&gt;
CommitDate: Fri Jun 16 10:58:25 2017 +0100

    pseudo: Handle too many files deadlock
    
    If we have large amounts of parallelism, pseudo can end up with too
    many open connections and will no longer accept further connections,
    hanging. This patch works around that by closing some clients, allowing
    turnover of connections and unblocking the system. The downside is a small
    but theoretical window of data loss. This is likely better than locking
    up entirely though. Discussions with Peter are onging about how we could
    better fix this.
    
    Signed-off-by: Richard Purdie &lt;richard.purdie@linuxfoundation.org&gt;


Is that a fix or a work-around?

Oh and would it be crazy to switch from select() to epoll() or even a polling abstraction library? Certainly select() is very portable but epoll has been around a while and performs better with more than 10s of file descriptors in benchmarks at least.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>74661</commentid>
    <comment_count>6</comment_count>
    <who name="Juro Bystricky">juro.bystricky</who>
    <bug_when>2017-06-29 20:40:37 +0000</bug_when>
    <thetext>(In reply to comment #5)
&gt; RP has pushed:
&gt; commit f3589f154dad1c92e599737623d392508810ae7e
&gt; Author:     Richard Purdie &lt;richard.purdie@linuxfoundation.org&gt;
&gt; AuthorDate: Tue Apr 25 15:25:54 2017 +0100
&gt; Commit:     Richard Purdie &lt;richard.purdie@linuxfoundation.org&gt;
&gt; CommitDate: Fri Jun 16 10:58:25 2017 +0100
&gt; 
&gt;     pseudo: Handle too many files deadlock
&gt;     
&gt;     If we have large amounts of parallelism, pseudo can end up with too
&gt;     many open connections and will no longer accept further connections,
&gt;     hanging. This patch works around that by closing some clients, allowing
&gt;     turnover of connections and unblocking the system. The downside is a
&gt; small
&gt;     but theoretical window of data loss. This is likely better than locking
&gt;     up entirely though. Discussions with Peter are onging about how we could
&gt;     better fix this.
&gt;     
&gt;     Signed-off-by: Richard Purdie &lt;richard.purdie@linuxfoundation.org&gt;
&gt; 
&gt; 
&gt; Is that a fix or a work-around?
&gt; 
&gt; Oh and would it be crazy to switch from select() to epoll() or even a
&gt; polling abstraction library? Certainly select() is very portable but epoll
&gt; has been around a while and performs better with more than 10s of file
&gt; descriptors in benchmarks at least.

I think epoll idea has a lot of merit. Not only for performance reasons but it also allows more than FD_SETSIZE file descriptors.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>74665</commentid>
    <comment_count>7</comment_count>
    <who name="Seebs">seebs</who>
    <bug_when>2017-06-29 21:28:39 +0000</bug_when>
    <thetext>we periodically get requests for BSD or Mac OS ports. They wouldn&apos;t work with epoll. I&apos;m not really familiar with epoll, but it strikes me as at least reasonable to consider, but there&apos;s a longer-term portability question.

Of course, it could also probably be encapsulated away a bit and I could support both.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>75808</commentid>
    <comment_count>8</comment_count>
    <who name="Seebs">seebs</who>
    <bug_when>2017-08-10 15:41:11 +0000</bug_when>
    <thetext>Sorry about the delay, sorta got crunch time on another project and can&apos;t easily reschedule.

Any resolution which drops clients will *potentially* have database corruption. It isn&apos;t super likely, but it&apos;s there as a potential.

The epoll solution is plausible, but breaks the Darwin port, which may be acceptable, but people pushed really hard for it.

I did some benchmarking, and I think we can address the corruption issue by improving/reworking FASTOP so that even FASTOP operations are round trips, they&apos;re just round trips which don&apos;t wait for the database operation before confirming that the server saw the message. That slows things down *slightly* compared to the current implementation, but is still dramatically faster than waiting for database operations. With that, it&apos;d be more practical to just cut clients off and let them reconnect later if they need to.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>77547</commentid>
    <comment_count>9</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2017-10-12 15:11:17 +0000</bug_when>
    <thetext>Fastop reply patch in oe-core, just waiting on agreement/disagreement about the patch for the pseudo repo.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>79699</commentid>
    <comment_count>10</comment_count>
    <who name="Alexander Kanavin">alex.kanavin</who>
    <bug_when>2018-03-05 06:49:41 +0000</bug_when>
    <thetext>I suppose this can be closed now?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>79753</commentid>
    <comment_count>11</comment_count>
    <who name="Ross Burton">ross.burton</who>
    <bug_when>2018-03-08 08:14:38 +0000</bug_when>
    <thetext>pseudo 1.9 has epoll and fastop improvements, so closing.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>