mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 23:21:29 +00:00 
			
		
		
		
	bpo-33694: Fix race condition in asyncio proactor (GH-7498)
The cancellation of an overlapped WSARecv() has a race condition which causes data loss because of the current implementation of proactor in asyncio. No longer cancel overlapped WSARecv() in _ProactorReadPipeTransport to work around the race condition. Remove the optimized recv_into() implementation to get simple implementation of pause_reading() using the single _pending_data attribute. Move _feed_data_to_bufferred_proto() to protocols.py. Remove set_protocol() method which became useless.
This commit is contained in:
		
							parent
							
								
									d3ed67d14e
								
							
						
					
					
						commit
						79790bc35f
					
				
					 6 changed files with 87 additions and 152 deletions
				
			
		| 
						 | 
				
			
			@ -189,3 +189,22 @@ def pipe_connection_lost(self, fd, exc):
 | 
			
		|||
 | 
			
		||||
    def process_exited(self):
 | 
			
		||||
        """Called when subprocess has exited."""
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def _feed_data_to_bufferred_proto(proto, data):
 | 
			
		||||
    data_len = len(data)
 | 
			
		||||
    while data_len:
 | 
			
		||||
        buf = proto.get_buffer(data_len)
 | 
			
		||||
        buf_len = len(buf)
 | 
			
		||||
        if not buf_len:
 | 
			
		||||
            raise RuntimeError('get_buffer() returned an empty buffer')
 | 
			
		||||
 | 
			
		||||
        if buf_len >= data_len:
 | 
			
		||||
            buf[:data_len] = data
 | 
			
		||||
            proto.buffer_updated(data_len)
 | 
			
		||||
            return
 | 
			
		||||
        else:
 | 
			
		||||
            buf[:buf_len] = data[:buf_len]
 | 
			
		||||
            proto.buffer_updated(buf_len)
 | 
			
		||||
            data = data[buf_len:]
 | 
			
		||||
            data_len = len(data)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue