mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 21:51:50 +00:00 
			
		
		
		
	bpo-39651: Fix asyncio proactor _write_to_self() (GH-22197)
Fix a race condition in the call_soon_threadsafe() method of
asyncio.ProactorEventLoop: do nothing if the self-pipe socket has
been closed.
(cherry picked from commit 1b0f0e3d7d)
Co-authored-by: Victor Stinner <vstinner@python.org>
			
			
This commit is contained in:
		
							parent
							
								
									34e3c7592b
								
							
						
					
					
						commit
						7dfcc8e079
					
				
					 3 changed files with 23 additions and 9 deletions
				
			
		|  | @ -791,8 +791,17 @@ def _loop_self_reading(self, f=None): | ||||||
|             f.add_done_callback(self._loop_self_reading) |             f.add_done_callback(self._loop_self_reading) | ||||||
| 
 | 
 | ||||||
|     def _write_to_self(self): |     def _write_to_self(self): | ||||||
|  |         # This may be called from a different thread, possibly after | ||||||
|  |         # _close_self_pipe() has been called or even while it is | ||||||
|  |         # running.  Guard for self._csock being None or closed.  When | ||||||
|  |         # a socket is closed, send() raises OSError (with errno set to | ||||||
|  |         # EBADF, but let's not rely on the exact error code). | ||||||
|  |         csock = self._csock | ||||||
|  |         if csock is None: | ||||||
|  |             return | ||||||
|  | 
 | ||||||
|         try: |         try: | ||||||
|             self._csock.send(b'\0') |             csock.send(b'\0') | ||||||
|         except OSError: |         except OSError: | ||||||
|             if self._debug: |             if self._debug: | ||||||
|                 logger.debug("Fail to write a null byte into the " |                 logger.debug("Fail to write a null byte into the " | ||||||
|  |  | ||||||
|  | @ -133,7 +133,9 @@ def _write_to_self(self): | ||||||
|         # a socket is closed, send() raises OSError (with errno set to |         # a socket is closed, send() raises OSError (with errno set to | ||||||
|         # EBADF, but let's not rely on the exact error code). |         # EBADF, but let's not rely on the exact error code). | ||||||
|         csock = self._csock |         csock = self._csock | ||||||
|         if csock is not None: |         if csock is None: | ||||||
|  |             return | ||||||
|  | 
 | ||||||
|         try: |         try: | ||||||
|             csock.send(b'\0') |             csock.send(b'\0') | ||||||
|         except OSError: |         except OSError: | ||||||
|  |  | ||||||
|  | @ -0,0 +1,3 @@ | ||||||
|  | Fix a race condition in the ``call_soon_threadsafe()`` method of | ||||||
|  | ``asyncio.ProactorEventLoop``: do nothing if the self-pipe socket has been | ||||||
|  | closed. | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Miss Islington (bot)
						Miss Islington (bot)