Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix Windows server not accepting requests after returning from loop.create_server()#134259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
Dreamsorcerer wants to merge2 commits intopython:main
base:main
Choose a base branch
Loading
fromDreamsorcerer:patch-8

Conversation

Dreamsorcerer
Copy link
Contributor

@DreamsorcererDreamsorcerer commentedMay 19, 2025
edited
Loading

We have a flaky test where, very occasionally on Windows, a request to the server immediately after loop.create_server() gets rejected.

Comparing the code between selector and proactor loops, it appears that the proactor loop would need one more loop iteration than the selector loop, if I'm understanding the code correctly.

The proactor code is nested in a loop registered with call_soon(), so it won't start executing until one loop iteration later than the selector loop does:

defloop(f=None):
try:
iffisnotNone:
conn,addr=f.result()
ifself._debug:
logger.debug("%r got a new connection from %r: %r",
server,addr,conn)
protocol=protocol_factory()
ifsslcontextisnotNone:
self._make_ssl_transport(
conn,protocol,sslcontext,server_side=True,
extra={'peername':addr},server=server,
ssl_handshake_timeout=ssl_handshake_timeout,
ssl_shutdown_timeout=ssl_shutdown_timeout)
else:
self._make_socket_transport(
conn,protocol,
extra={'peername':addr},server=server)
ifself.is_closed():
return
f=self._proactor.accept(sock)
exceptOSErrorasexc:
ifsock.fileno()!=-1:
self.call_exception_handler({
'message':'Accept failed on a socket',
'exception':exc,
'socket':trsock.TransportSocket(sock),
})
sock.close()
elifself._debug:
logger.debug("Accept failed on socket %r",
sock,exc_info=True)
exceptexceptions.CancelledError:
sock.close()
else:
self._accept_futures[sock.fileno()]=f
f.add_done_callback(loop)
self.call_soon(loop)

Compared to:

self._check_closed()
handle=events.Handle(callback,args,self,None)
key=self._selector.get_map().get(fd)
ifkeyisNone:
self._selector.register(fd,selectors.EVENT_READ,
(handle,None))
else:
mask, (reader,writer)=key.events,key.data
self._selector.modify(fd,mask|selectors.EVENT_READ,
(handle,writer))
ifreaderisnotNone:
reader.cancel()

i.e. selector.register() is called in loop iteration 0, whereas proactor.accept() is called in loop iteration 1.

@DreamsorcererDreamsorcerer changed the titleFix Windows server not accepting requests when returning from loop.create_server()Fix Windows server not accepting requests after returning from loop.create_server()May 19, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@1st11st1Awaiting requested review from 1st11st1 is a code owner

@asvetlovasvetlovAwaiting requested review from asvetlovasvetlov is a code owner

@kumaraditya303kumaraditya303Awaiting requested review from kumaraditya303kumaraditya303 is a code owner

@willingcwillingcAwaiting requested review from willingcwillingc is a code owner

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

1 participant
@Dreamsorcerer

[8]ページ先頭

©2009-2025 Movatter.jp