@@ -471,6 +471,57 @@ def test_create_unix_server_path_stream_bittype(self):
471471 finally :
472472 os .unlink (fn )
473473
474+ @unittest .skipUnless (sys .platform .startswith ('linux' ), 'requires epoll' )
475+ def test_epollhup (self ):
476+ SIZE = 50
477+ eof = False
478+ done = False
479+ recvd = b''
480+
481+ class Proto (asyncio .BaseProtocol ):
482+ def connection_made (self , tr ):
483+ tr .write (b'hello' )
484+ self .data = bytearray (SIZE )
485+ self .buf = memoryview (self .data )
486+
487+ def get_buffer (self , sizehint ):
488+ return self .buf
489+
490+ def buffer_updated (self , nbytes ):
491+ nonlocal recvd
492+ recvd += self .buf [:nbytes ]
493+
494+ def eof_received (self ):
495+ nonlocal eof
496+ eof = True
497+
498+ def connection_lost (self , exc ):
499+ nonlocal done
500+ done = exc
501+
502+ async def test ():
503+ with tempfile .TemporaryDirectory () as td :
504+ sock_name = os .path .join (td , 'sock' )
505+ srv = await self .loop .create_unix_server (Proto , sock_name )
506+
507+ s = socket .socket (socket .AF_UNIX )
508+ with s :
509+ s .setblocking (False )
510+ await self .loop .sock_connect (s , sock_name )
511+ d = await self .loop .sock_recv (s , 100 )
512+ self .assertEqual (d , b'hello' )
513+
514+ # IMPORTANT: overflow recv buffer and close immediately
515+ await self .loop .sock_sendall (s , b'a' * (SIZE + 1 ))
516+
517+ srv .close ()
518+ await srv .wait_closed ()
519+
520+ self .loop .run_until_complete (test ())
521+ self .assertTrue (eof )
522+ self .assertIsNone (done )
523+ self .assertEqual (recvd , b'a' * (SIZE + 1 ))
524+
474525
475526class Test_AIO_Unix (_TestUnix , tb .AIOTestCase ):
476527 pass
0 commit comments