RESOLVED FIXED172774
test-webkitpy: stop forking unsafely from within a spawned process
https://bugs.webkit.org/show_bug.cgi?id=172774
Summary test-webkitpy: stop forking unsafely from within a spawned process
Dean Johnson
Reported 2017-05-31 13:58:10 PDT
webkitpy when running unit tests forks unsafely from within a spawned process while running the tests.
Attachments
Patch (2.30 KB, patch)
2017-05-31 14:06 PDT, Dean Johnson
no flags
Patch (2.58 KB, patch)
2017-05-31 16:54 PDT, Dean Johnson
no flags
Patch (2.43 KB, patch)
2017-06-02 17:48 PDT, Dean Johnson
no flags
Dean Johnson
Comment 1 2017-05-31 13:58:34 PDT
Radar WebKit Bug Importer
Comment 2 2017-05-31 13:59:21 PDT
Dean Johnson
Comment 3 2017-05-31 14:06:07 PDT
Dean Johnson
Comment 4 2017-05-31 16:54:58 PDT
Dean Johnson
Comment 5 2017-05-31 16:57:21 PDT
Last patch changes instantiation of self._browser by instantiating it as 'None' in the __init__ function, then actually assigning it a mechanize.Browser() object if we attempt to use self._browser (in Builder.force_build) when it hasn't been initialized. This is similar to how access is done for statusserver and bugzilla interactions.
Alexey Proskuryakov
Comment 6 2017-05-31 19:20:23 PDT
Comment on attachment 311657 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=311657&action=review Nice temporary hack! This of course relies on not testing the force_build function, which is not great, and on not testing any other code touching objects that are unsafe to use while forking. > Tools/Scripts/webkitpy/common/net/buildbot/buildbot.py:135 > + # Initialize here since Mechanize will spawn a new process for Browser, which is > + # incompatible with using Python's multiprocessing safely. I think that this comment may be a bit too vague. How about something like "Creating Browser lazily avoids doing that as part of test-webkitpy, which is unsafe due to other tests using Python's multiprocessing"? My comment says something different than yours, and I'm not entirely sure which is right. I don't see how the forking in Mechanize would be a problem, I think that it's regular run-webkit-tests forking that becomes a problem.
Dean Johnson
Comment 7 2017-06-01 11:16:27 PDT
(In reply to Alexey Proskuryakov from comment #6) > Comment on attachment 311657 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=311657&action=review > > Nice temporary hack! This of course relies on not testing the force_build > function, which is not great, and on not testing any other code touching > objects that are unsafe to use while forking. Actually, bugzilla and statusserver tests use MockBrowser() objects for testing so I think we could still test this codepath if we wanted, and all we'd need to do is something like this: def test_force_build(self): from webkitpy.<something> import MockBrowser builder = Builder('test_builder') mock_browser = MockBrowser(args) # Setup return functions for Mock builder._browser = mock_browser builder.force_build() # Validate things ran as expected > > > Tools/Scripts/webkitpy/common/net/buildbot/buildbot.py:135 > > + # Initialize here since Mechanize will spawn a new process for Browser, which is > > + # incompatible with using Python's multiprocessing safely. > > I think that this comment may be a bit too vague. How about something like > "Creating Browser lazily avoids doing that as part of test-webkitpy, which > is unsafe due to other tests using Python's multiprocessing"? > > My comment says something different than yours, and I'm not entirely sure > which is right. I don't see how the forking in Mechanize would be a problem, > I think that it's regular run-webkit-tests forking that becomes a problem. I feel my comment is more descriptive as to _why_ the logic now lives where it does, but I agree it could be improved upon. Maybe something like this would be better: "Python2.7's multiprocessing module does not safely allow of spawning processes from within already spawned multiprocessing.Process objects. Because testwebkit-py uses multiprocessing.Process based Runners to execute tests quickly, we can not safely instantiate a Mechanize browser while running webkitpy tests."
Dean Johnson
Comment 8 2017-06-02 17:48:25 PDT
Dean Johnson
Comment 9 2017-06-02 17:58:41 PDT
Removed comments Alexey and I were discussing since they were incorrect.
WebKit Commit Bot
Comment 10 2017-06-06 13:39:11 PDT
Comment on attachment 311890 [details] Patch Clearing flags on attachment: 311890 Committed r217855: <http://trac.webkit.org/changeset/217855>
WebKit Commit Bot
Comment 11 2017-06-06 13:39:13 PDT
All reviewed patches have been landed. Closing bug.
Note You need to log in before you can comment on or make changes to this bug.