~ubuntu-branches/ubuntu/trusty/swift/trusty

« back to all changes in this revision

Viewing changes to swift/proxy/controllers/base.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-09-26 09:19:43 UTC
  • mfrom: (1.2.14)
  • Revision ID: package-import@ubuntu.com-20120926091943-kiooorf6tyy5yi7m
Tags: 1.7.4-0ubuntu1
* New upstream release. 
* debian/rules: Fail to build the packages if testsuite fails.

Show diffs side-by-side

added added

removed removed

Lines of Context:
505
505
            if getattr(source, 'swift_conn', None):
506
506
                self.close_swift_conn(source)
507
507
 
508
 
    def _make_app_iter(self, node, source, response):
 
508
    def _make_app_iter(self, node, source):
509
509
        """
510
510
        Returns an iterator over the contents of the source (via its read
511
511
        func).  There is also quite a bit of cleanup to ensure garbage
512
512
        collection works and the underlying socket of the source is closed.
513
513
 
514
 
        :param response: The webob.Response object this iterator should be
515
 
                         assigned to via response.app_iter.
516
514
        :param source: The httplib.Response object this iterator should read
517
515
                       from.
518
516
        :param node: The node the source is reading from, for logging purposes.
519
517
        """
520
518
        try:
521
 
            try:
522
 
                # Spawn reader to read from the source and place in the queue.
523
 
                # We then drop any reference to the source or node, for garbage
524
 
                # collection purposes.
525
 
                queue = Queue(1)
526
 
                spawn_n(self._make_app_iter_reader, node, source, queue,
527
 
                        self.app.logger.thread_locals)
528
 
                source = node = None
529
 
                while True:
530
 
                    chunk = queue.get(timeout=self.app.node_timeout)
531
 
                    if isinstance(chunk, bool):  # terminator
532
 
                        success = chunk
533
 
                        if not success:
534
 
                            raise Exception(_('Failed to read all data'
535
 
                                              ' from the source'))
536
 
                        break
537
 
                    yield chunk
538
 
            except Empty:
539
 
                raise ChunkReadTimeout()
540
 
            except (GeneratorExit, Timeout):
541
 
                self.app.logger.warn(_('Client disconnected on read'))
542
 
            except Exception:
543
 
                self.app.logger.exception(_('Trying to send to client'))
544
 
                raise
545
 
        finally:
546
 
            response.app_iter = None
 
519
            # Spawn reader to read from the source and place in the queue.
 
520
            # We then drop any reference to the source or node, for garbage
 
521
            # collection purposes.
 
522
            queue = Queue(1)
 
523
            spawn_n(self._make_app_iter_reader, node, source, queue,
 
524
                    self.app.logger.thread_locals)
 
525
            source = node = None
 
526
            while True:
 
527
                chunk = queue.get(timeout=self.app.node_timeout)
 
528
                if isinstance(chunk, bool):  # terminator
 
529
                    success = chunk
 
530
                    if not success:
 
531
                        raise Exception(_('Failed to read all data'
 
532
                                          ' from the source'))
 
533
                    break
 
534
                yield chunk
 
535
        except Empty:
 
536
            raise ChunkReadTimeout()
 
537
        except (GeneratorExit, Timeout):
 
538
            self.app.logger.warn(_('Client disconnected on read'))
 
539
        except Exception:
 
540
            self.app.logger.exception(_('Trying to send to client'))
 
541
            raise
547
542
 
548
543
    def close_swift_conn(self, src):
549
544
        try:
656
651
                        self.close_swift_conn(src)
657
652
 
658
653
                res = Response(request=req, conditional_response=True)
659
 
                res.app_iter = self._make_app_iter(node, source, res)
 
654
                res.app_iter = self._make_app_iter(node, source)
660
655
                # See NOTE: swift_conn at top of file about this.
661
656
                res.swift_conn = source.swift_conn
662
657
                update_headers(res, source.getheaders())