Mercurial > python-hglib
comparison hglib/client.py @ 189:8054e925d9c7
client: kill the server on unrecoverable communication errors (issue5516)
Once an unrecoverable communication error occurs between the client and server,
it's no longer safe to send further commands to the same server.
On Windows, attempting to do so is known to cause lockups and memory leaks.
Close the client and kill the server when an such an error occurs. This way,
any further commands will fail gracefully with ValueError until the client
is reopened.
author | Gábor Stefanik <gabor.stefanik@nng.com> |
---|---|
date | Mon, 21 Aug 2017 17:02:14 +0200 |
parents | 5609a21fe39a |
children | f38bc0569671 |
comparison
equal
deleted
inserted
replaced
188:5609a21fe39a | 189:8054e925d9c7 |
---|---|
137 ", got %r" % msg[1]) | 137 ", got %r" % msg[1]) |
138 | 138 |
139 def _readchannel(self): | 139 def _readchannel(self): |
140 data = self.server.stdout.read(hgclient.outputfmtsize) | 140 data = self.server.stdout.read(hgclient.outputfmtsize) |
141 if not data: | 141 if not data: |
142 self.close() | |
142 raise error.ServerError() | 143 raise error.ServerError() |
143 channel, length = struct.unpack(hgclient.outputfmt, data) | 144 channel, length = struct.unpack(hgclient.outputfmt, data) |
144 if channel in b('IL'): | 145 if channel in b('IL'): |
145 return channel, length | 146 return channel, length |
146 else: | 147 else: |
188 # result channel, command finished | 189 # result channel, command finished |
189 elif channel == b('r'): | 190 elif channel == b('r'): |
190 return struct.unpack(hgclient.retfmt, data)[0] | 191 return struct.unpack(hgclient.retfmt, data)[0] |
191 # a channel that we don't know and can't ignore | 192 # a channel that we don't know and can't ignore |
192 elif channel.isupper(): | 193 elif channel.isupper(): |
194 self.close() | |
193 raise error.ResponseError( | 195 raise error.ResponseError( |
194 "unexpected data on required channel '%s'" % channel) | 196 "unexpected data on required channel '%s'" % channel) |
195 # optional channel | 197 # optional channel |
196 else: | 198 else: |
197 pass | 199 pass |