/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/smart/message.py

  • Committer: John Arbash Meinel
  • Date: 2011-04-20 14:27:19 UTC
  • mto: This revision was merged to the branch mainline in revision 5837.
  • Revision ID: john@arbash-meinel.com-20110420142719-advs1k5vztqzbrgv
Fix bug #767177. Be more agressive with file.close() calls.

Our test suite gets a number of thread leaks and failures because it happens to get async
SFTPFile.close() calls. (if an SFTPFile closes due to __del__ it is done as an async request,
while if you call SFTPFile.close() it is done as a synchronous request.)
We have a couple other cases, probably. Namely SFTPTransport.get() also does an async
prefetch of the content, so if you don't .read() you'll also leak threads that think they
are doing work that you want.

The biggest change here, though, is using a try/finally in a generator, which is not 
python2.4 compatible.

Show diffs side-by-side

added added

removed removed

Lines of Context:
303
303
            mutter('   result:   %r', self.args)
304
304
        if self.status == 'E':
305
305
            self._wait_for_response_end()
306
 
            _translate_error(self.args)
 
306
            _raise_smart_server_error(self.args)
307
307
        return tuple(self.args)
308
308
 
309
309
    def read_body_bytes(self, count=-1):
335
335
                yield bytes_part
336
336
            self._read_more()
337
337
        if self._body_stream_status == 'E':
338
 
            _translate_error(self._body_error_args)
 
338
            _raise_smart_server_error(self._body_error_args)
339
339
 
340
340
    def cancel_read_body(self):
341
341
        self._wait_for_response_end()
342
342
 
343
343
 
344
 
def _translate_error(error_tuple):
345
 
    # Many exceptions need some state from the requestor to be properly
346
 
    # translated (e.g. they need a branch object).  So this only translates a
347
 
    # few errors, and the rest are turned into a generic ErrorFromSmartServer.
348
 
    error_name = error_tuple[0]
349
 
    error_args = error_tuple[1:]
350
 
    if error_name == 'UnknownMethod':
351
 
        raise errors.UnknownSmartMethod(error_args[0])
352
 
    if error_name == 'LockContention':
353
 
        raise errors.LockContention('(remote lock)')
354
 
    elif error_name == 'LockFailed':
355
 
        raise errors.LockFailed(*error_args[:2])
356
 
    elif error_name == 'FileExists':
357
 
        raise errors.FileExists(error_args[0])
358
 
    elif error_name == 'NoSuchFile':
359
 
        raise errors.NoSuchFile(error_args[0])
360
 
    else:
361
 
        raise errors.ErrorFromSmartServer(error_tuple)
 
344
def _raise_smart_server_error(error_tuple):
 
345
    """Raise exception based on tuple received from smart server
 
346
 
 
347
    Specific error translation is handled by bzrlib.remote._translate_error
 
348
    """
 
349
    if error_tuple[0] == 'UnknownMethod':
 
350
        raise errors.UnknownSmartMethod(error_tuple[1])
 
351
    raise errors.ErrorFromSmartServer(error_tuple)