Mercurial > public > mercurial-scm > hg
comparison tests/tinyproxy.py @ 18519:ca430fb6a668 stable
tests: fix toctou race in tinyproxy.py (issue3795)
test-http-proxy.t sometimes failed with:
File ".../tests/tinyproxy.py", line 110, in _read_write
data = i.recv(8192)
error: (104, 'Connection reset by peer')
This might have started showing up with a9fd11ffa13f ... but it has apparently
also been seen before. I don't see anything in a9fd11ffa13f that can explain
it. It seems to be a race in test, in the tinyproxy helper:
Tinyproxy found an incoming socket using select(). It would break the loop if
an error had been detected on the socket, but there was no error and it tried
to recv() from the socket. That failed - apparently because it had been reset
after select().
Errors in the recv() will now be caught and will break the loop like errors
detected by select() would.
(send() could also fail in a similar way ... but using the same solution there
and losing data we have read doesn't feel right.)
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Thu, 31 Jan 2013 19:13:13 +0100 |
parents | 7292a4618f46 |
children | 328739ea70c3 |
comparison
equal
deleted
inserted
replaced
18518:0324a1d88a53 | 18519:ca430fb6a668 |
---|---|
105 for i in ins: | 105 for i in ins: |
106 if i is soc: | 106 if i is soc: |
107 out = self.connection | 107 out = self.connection |
108 else: | 108 else: |
109 out = soc | 109 out = soc |
110 data = i.recv(8192) | 110 try: |
111 data = i.recv(8192) | |
112 except socket.error: | |
113 break | |
111 if data: | 114 if data: |
112 out.send(data) | 115 out.send(data) |
113 count = 0 | 116 count = 0 |
114 else: | 117 else: |
115 print "\t" "idle", count | 118 print "\t" "idle", count |