8000 extmod/uasyncio: Fix start_server and wait_closed race condition. · codemee/micropython@de2e081 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit de2e081

Browse files
miguelgrinbergdpgeorge
authored andcommitted
extmod/uasyncio: Fix start_server and wait_closed race condition.
This fix prevents server.wait_closed() from raising an AttributeError when trying to access s 8000 erver.task. This can happen if it is called immediately after start_server().
1 parent 525a920 commit de2e081

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

extmod/uasyncio/stream.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ async def _serve(self, cb, host, port, backlog):
112112
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
113113
s.bind(ai[-1])
114114
s.listen(backlog)
115-
self.task = core.cur_task
116115
# Accept incoming connections
117116
while True:
118117
try:
@@ -135,7 +134,7 @@ async def _serve(self, cb, host, port, backlog):
135134
# TODO could use an accept-callback on socket read activity instead of creating a task
136135
async def start_server(cb, host, port, backlog=5):
137136
s = Server()
138-
core.create_task(s._serve(cb, host, port, backlog))
137+
s.task = core.create_task(s._serve(cb, host, port, backlog))
139138
return s
140139

141140

0 commit comments

Comments
 (0)
0