[MERGE] Re: [Bug 115781] Re: traceback on smart server when branching/pulling (win32)

Andrew Bennetts andrew at canonical.com
Tue Dec 18 14:27:07 GMT 2007


[moving discussion to list so that people can review the code]

Alexander Belchenko wrote:
> Andrew Bennetts пишет:
[...]
> > connection.  My guess is that we're getting a 10055 (WSAENOBUFS) because
> > we're trying to write several megabytes to the socket in a single call,
> > which would trip over <http://support.microsoft.com/kb/201213>.
> > 
> > If that hypothesis is right, then a patch like this should fix the
> > problem:
> > 
> > === modified file 'bzrlib/smart/medium.py'
> > --- bzrlib/smart/medium.py      2007-12-03 16:39:11 +0000
> > +++ bzrlib/smart/medium.py      2007-12-18 00:04:58 +0000
> > @@ -177,7 +177,10 @@
> >          self.finished = True
> >  
> >      def _write_out(self, bytes):
> > -        self.socket.sendall(bytes)
> > +        while bytes:
> > +            chunk = bytes[:65536]
> > +            bytes = bytes[65536:]
> > +            self.socket.sendall(chunk)
> >  
> >  
> >  class SmartServerPipeStreamMedium(SmartServerStreamMedium):
> > 
> > (i.e., never write more than 64k at a time in SmartServerSocketStreamMedium)
> 
> This patch helps. Do you need more testing from me?
> If not -- please, merge it to bzr.dev.

Sending to the list for feedback.

It's probably better to write the loop as:

        chunk_size = 2**16
        pos = 0
        while pos < len(bytes):
            chunk = bytes[pos:pos+chunk_size]
            pos += chunk_size
            self.socket.sendall(chunk)

This way we avoid copying multi-megabyte strings in memory repeatedly.

Attached is the patch for review.  It has the improved loop, a comment, and a
NEWS entry.  See https://bugs.launchpad.net/bzr/+bug/115781 for the complete
discussion about the problem.

Alexander, thanks for testing the patches!

-Andrew.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: sendall-limit.patch
Type: text/x-diff
Size: 1064 bytes
Desc: not available
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20071219/df3b5a8b/attachment.bin 


More information about the bazaar mailing list