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
=== modified file 'bzrlib/tests/__init__.py'
--- bzrlib/tests/__init__.py 2011-05-26 08:05:45 +0000
+++ bzrlib/tests/__init__.py 2011-05-27 05:54:44 +0000
@@ -2013,7 +2013,7 @@
2013 def start_bzr_subprocess(self, process_args, env_changes=None,2013 def start_bzr_subprocess(self, process_args, env_changes=None,
2014 skip_if_plan_to_signal=False,2014 skip_if_plan_to_signal=False,
2015 working_dir=None,2015 working_dir=None,
2016 allow_plugins=False):2016 allow_plugins=False, stderr=subprocess.PIPE):
2017 """Start bzr in a subprocess for testing.2017 """Start bzr in a subprocess for testing.
20182018
2019 This starts a new Python interpreter and runs bzr in there.2019 This starts a new Python interpreter and runs bzr in there.
@@ -2031,6 +2031,9 @@
2031 :param skip_if_plan_to_signal: raise TestSkipped when true and system2031 :param skip_if_plan_to_signal: raise TestSkipped when true and system
2032 doesn't support signalling subprocesses.2032 doesn't support signalling subprocesses.
2033 :param allow_plugins: If False (default) pass --no-plugins to bzr.2033 :param allow_plugins: If False (default) pass --no-plugins to bzr.
2034 :param stderr: file to use for the subprocess's stderr. Valid values
2035 are those valid for the stderr argument of `subprocess.Popen`.
2036 Default value is ``subprocess.PIPE``.
20342037
2035 :returns: Popen object for the started process.2038 :returns: Popen object for the started process.
2036 """2039 """
@@ -2071,7 +2074,7 @@
2071 command.extend(process_args)2074 command.extend(process_args)
2072 process = self._popen(command, stdin=subprocess.PIPE,2075 process = self._popen(command, stdin=subprocess.PIPE,
2073 stdout=subprocess.PIPE,2076 stdout=subprocess.PIPE,
2074 stderr=subprocess.PIPE)2077 stderr=stderr)
2075 finally:2078 finally:
2076 restore_environment()2079 restore_environment()
2077 if cwd is not None:2080 if cwd is not None:
20782081
=== modified file 'bzrlib/tests/test_import_tariff.py'
--- bzrlib/tests/test_import_tariff.py 2011-05-03 23:16:56 +0000
+++ bzrlib/tests/test_import_tariff.py 2011-05-27 05:54:44 +0000
@@ -62,7 +62,7 @@
62 self.preserved_env_vars[name] = os.environ.get(name)62 self.preserved_env_vars[name] = os.environ.get(name)
63 super(TestImportTariffs, self).setUp()63 super(TestImportTariffs, self).setUp()
6464
65 def start_bzr_subprocess_with_import_check(self, args):65 def start_bzr_subprocess_with_import_check(self, args, stderr_file=None):
66 """Run a bzr process and capture the imports.66 """Run a bzr process and capture the imports.
6767
68 This is fairly expensive because we start a subprocess, so we aim to68 This is fairly expensive because we start a subprocess, so we aim to
@@ -187,8 +187,11 @@
187 def test_simple_serve(self):187 def test_simple_serve(self):
188 # 'serve' in a default format working tree shouldn't need many modules188 # 'serve' in a default format working tree shouldn't need many modules
189 tree = self.make_branch_and_tree('.')189 tree = self.make_branch_and_tree('.')
190 # Capture the bzr serve process' stderr in a file to avoid deadlocks
191 # while the smart client interacts with it.
192 stderr_file = open('bzr-serve.stderr', 'w')
190 process = self.start_bzr_subprocess_with_import_check(['serve',193 process = self.start_bzr_subprocess_with_import_check(['serve',
191 '--inet', '-d', tree.basedir])194 '--inet', '-d', tree.basedir], stderr_file=stderr_file)
192 url = 'bzr://localhost/'195 url = 'bzr://localhost/'
193 self.permit_url(url)196 self.permit_url(url)
194 client_medium = medium.SmartSimplePipesClientMedium(197 client_medium = medium.SmartSimplePipesClientMedium(
@@ -200,6 +203,9 @@
200 process.stdin = None203 process.stdin = None
201 (out, err) = self.finish_bzr_subprocess(process,204 (out, err) = self.finish_bzr_subprocess(process,
202 universal_newlines=False)205 universal_newlines=False)
206 stderr_file.close()
207 with open('bzr-serve.stderr', 'r') as stderr_file:
208 err = stderr_file.read()
203 self.check_forbidden_modules(err,209 self.check_forbidden_modules(err,
204 ['bzrlib.annotate',210 ['bzrlib.annotate',
205 'bzrlib.atomicfile',211 'bzrlib.atomicfile',
206212
=== modified file 'doc/en/release-notes/bzr-2.4.txt'
--- doc/en/release-notes/bzr-2.4.txt 2011-05-26 20:24:20 +0000
+++ doc/en/release-notes/bzr-2.4.txt 2011-05-27 05:54:44 +0000
@@ -59,6 +59,12 @@
59 suite. This can include new facilities for writing tests, fixes to 59 suite. This can include new facilities for writing tests, fixes to
60 spurious test failures and changes to the way things should be tested.60 spurious test failures and changes to the way things should be tested.
6161
62* Fix deadlock in `TestImportTariffs.test_simple_serve` when stderr gets
63 more output than fits in the default buffer. This was happening on the
64 Windows buildslave, and could easily happen in other circumstances where
65 the default OS buffer size for pipes is small or the ``python -v``
66 output is large. (Andrew Bennetts, #784802)
67
6268
63bzr 2.4b369bzr 2.4b3
64#########70#########