Merge lp:~spiv/bzr/import-tariff-test-subprocess-deadlock into lp:bzr

Proposed by Andrew Bennetts
Status: Merged
Merged at revision: 5929
Proposed branch: lp:~spiv/bzr/import-tariff-test-subprocess-deadlock
Merge into: lp:bzr
Diff against target: 84 lines (+19/-4)
3 files modified
bzrlib/tests/__init__.py (+5/-2)
bzrlib/tests/test_import_tariff.py (+8/-2)
doc/en/release-notes/bzr-2.4.txt (+6/-0)
To merge this branch: bzr merge lp:~spiv/bzr/import-tariff-test-subprocess-deadlock
Reviewer Review Type Date Requested Status
Vincent Ladeuil Needs Fixing
bzr-core Pending
Review via email: mp+62592@code.launchpad.net

Description of the change

In theory this branch should fix the deadlock in test_import_tariff on the Windows buildslave in babune. The theory is that the stderr pipe has a finite buffer size, and we don't read from it until the process finishes, so if there's enough output the subprocess will hang and so will our test. (stdout and stdin don't need any special attention here because they are managed by the smart server protocol code, so they should be fine because the smart protocol code always knows when it can read from stdout.)

It would be good to get confirmation from Vincent that does work before landing it; I have a hazy post-sprint memory that perhaps he already did and it failed. If it doesn't we'll need to dig deeper to find out why it's still hanging.

To post a comment you must log in.
Revision history for this message
Vincent Ladeuil (vila) wrote :

I will retry it but it wasn't addressing the problem on OSX (easier testing there for me).

Also note http://pad.lv/625551 which shares some bad smells with this issue.

And also http://pad.lv/788235 which also involves bzr_serve and hangs in a maverick chroot (easier to reproduce, several tests currently repeatedly fail (with some variants regarding which ones fail)).

I think all of them are revealing a racing condition we never encounter before but was always present.

Oh, and of course the breakin tests which have now been deleted by poolie were also probably hitting the same problem but were blacklisted on babune.

This bug had fun with us for too long, I officially call for a war against it ;)

Revision history for this message
Vincent Ladeuil (vila) wrote :

Confirmed, still hanging on OSX :-/

Revision history for this message
John A Meinel (jameinel) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 05/27/2011 09:48 AM, Vincent Ladeuil wrote:
> Confirmed, still hanging on OSX :-/

Can we use a temporary file instead of a file in the current directory?
Otherwise I think this is better than before, regardless of whether it
makes the specific bits better.

John
=:->

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk3fXRQACgkQJdeBCYSNAAPOZACfVtO109OSFV56o9yewsYU4U/v
fgYAoNP766/neOvk1Yme9n+wCImqNTWE
=awSA
-----END PGP SIGNATURE-----

Revision history for this message
John A Meinel (jameinel) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 05/27/2011 10:15 AM, John A Meinel wrote:
> On 05/27/2011 09:48 AM, Vincent Ladeuil wrote:
>> Confirmed, still hanging on OSX :-/
>
> Can we use a temporary file instead of a file in the current directory?
> Otherwise I think this is better than before, regardless of whether it
> makes the specific bits better.
>
> John
> =:->
>

I take that back. I think the test is already isolated in a temp dir,
just using a local file is fine.
John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk3fXfoACgkQJdeBCYSNAAMEswCdE2bXxwtUiw5OUt3W270Ghskx
pEYAn1aVf4WNQZBKqPhUCA4cY3NO7lnL
=jwFN
-----END PGP SIGNATURE-----

Revision history for this message
Vincent Ladeuil (vila) wrote :

This proposal is itself in a deadlock state :)

It doesn't address the bug but we still don't know why.

Marking it as WIP until we know better and it's resubmitted or we found a different approach and it's abandoned.

review: Needs Fixing
Revision history for this message
Vincent Ladeuil (vila) wrote :

Rejoice !

The plan was good ! The implementation... missed a tiny tiny little bit :)

I even wonder what happened there, I can only suspect you tested it successfully on the failing test, tried all import tests, realized one was broken, fixed it... without realizing you broke the first one ;)

But anyway, well done !

The missing tiny little bit is at lp:~vila/bzr/import-tariff-test-subprocess-deadlock which I will land, because that will be a nice way to end the week !

The war is over ! This bug is dead !

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/tests/__init__.py'
2--- bzrlib/tests/__init__.py 2011-05-26 08:05:45 +0000
3+++ bzrlib/tests/__init__.py 2011-05-27 05:54:44 +0000
4@@ -2013,7 +2013,7 @@
5 def start_bzr_subprocess(self, process_args, env_changes=None,
6 skip_if_plan_to_signal=False,
7 working_dir=None,
8- allow_plugins=False):
9+ allow_plugins=False, stderr=subprocess.PIPE):
10 """Start bzr in a subprocess for testing.
11
12 This starts a new Python interpreter and runs bzr in there.
13@@ -2031,6 +2031,9 @@
14 :param skip_if_plan_to_signal: raise TestSkipped when true and system
15 doesn't support signalling subprocesses.
16 :param allow_plugins: If False (default) pass --no-plugins to bzr.
17+ :param stderr: file to use for the subprocess's stderr. Valid values
18+ are those valid for the stderr argument of `subprocess.Popen`.
19+ Default value is ``subprocess.PIPE``.
20
21 :returns: Popen object for the started process.
22 """
23@@ -2071,7 +2074,7 @@
24 command.extend(process_args)
25 process = self._popen(command, stdin=subprocess.PIPE,
26 stdout=subprocess.PIPE,
27- stderr=subprocess.PIPE)
28+ stderr=stderr)
29 finally:
30 restore_environment()
31 if cwd is not None:
32
33=== modified file 'bzrlib/tests/test_import_tariff.py'
34--- bzrlib/tests/test_import_tariff.py 2011-05-03 23:16:56 +0000
35+++ bzrlib/tests/test_import_tariff.py 2011-05-27 05:54:44 +0000
36@@ -62,7 +62,7 @@
37 self.preserved_env_vars[name] = os.environ.get(name)
38 super(TestImportTariffs, self).setUp()
39
40- def start_bzr_subprocess_with_import_check(self, args):
41+ def start_bzr_subprocess_with_import_check(self, args, stderr_file=None):
42 """Run a bzr process and capture the imports.
43
44 This is fairly expensive because we start a subprocess, so we aim to
45@@ -187,8 +187,11 @@
46 def test_simple_serve(self):
47 # 'serve' in a default format working tree shouldn't need many modules
48 tree = self.make_branch_and_tree('.')
49+ # Capture the bzr serve process' stderr in a file to avoid deadlocks
50+ # while the smart client interacts with it.
51+ stderr_file = open('bzr-serve.stderr', 'w')
52 process = self.start_bzr_subprocess_with_import_check(['serve',
53- '--inet', '-d', tree.basedir])
54+ '--inet', '-d', tree.basedir], stderr_file=stderr_file)
55 url = 'bzr://localhost/'
56 self.permit_url(url)
57 client_medium = medium.SmartSimplePipesClientMedium(
58@@ -200,6 +203,9 @@
59 process.stdin = None
60 (out, err) = self.finish_bzr_subprocess(process,
61 universal_newlines=False)
62+ stderr_file.close()
63+ with open('bzr-serve.stderr', 'r') as stderr_file:
64+ err = stderr_file.read()
65 self.check_forbidden_modules(err,
66 ['bzrlib.annotate',
67 'bzrlib.atomicfile',
68
69=== modified file 'doc/en/release-notes/bzr-2.4.txt'
70--- doc/en/release-notes/bzr-2.4.txt 2011-05-26 20:24:20 +0000
71+++ doc/en/release-notes/bzr-2.4.txt 2011-05-27 05:54:44 +0000
72@@ -59,6 +59,12 @@
73 suite. This can include new facilities for writing tests, fixes to
74 spurious test failures and changes to the way things should be tested.
75
76+* Fix deadlock in `TestImportTariffs.test_simple_serve` when stderr gets
77+ more output than fits in the default buffer. This was happening on the
78+ Windows buildslave, and could easily happen in other circumstances where
79+ the default OS buffer size for pipes is small or the ``python -v``
80+ output is large. (Andrew Bennetts, #784802)
81+
82
83 bzr 2.4b3
84 #########