Skip to content

Commit

Permalink
Investigation of Linux freezes #2.
Browse files Browse the repository at this point in the history
  • Loading branch information
cheatfate authored and zah committed Feb 18, 2021
1 parent bb176ba commit cf42a54
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions chronos/asyncloop.nim
Original file line number Diff line number Diff line change
Expand Up @@ -633,9 +633,12 @@ elif unixPlatform:

proc continuation(udata: pointer) =
if SocketHandle(fd) in loop.selector:
echo "closeSocket() continuation unregistering"
unregister(fd)
echo "closeSocket() continuation close()"
close(SocketHandle(fd))
if not isNil(aftercb):
echo "closeSocket() invoke user-callback"
aftercb(nil)

withData(loop.selector, int(fd), adata) do:
Expand All @@ -645,17 +648,20 @@ elif unixPlatform:
# from system queue for this reader and writer.

if not(isNil(adata.reader.function)):
echo "closeSocket() scheduling reader"
loop.callbacks.addLast(adata.reader)
adata.reader = default(AsyncCallback)

if not(isNil(adata.writer.function)):
echo "closeSocket() scheduling writer"
loop.callbacks.addLast(adata.writer)
adata.writer = default(AsyncCallback)

# We can't unregister file descriptor from system queue here, because
# in such case processing queue will stuck on poll() call, because there
# can be no file descriptors registered in system queue.
var acb = AsyncCallback(function: continuation)
echo "closeSocket() scheduling actual close"
loop.callbacks.addLast(acb)

proc closeHandle*(fd: AsyncFD, aftercb: CallbackFunc = nil) {.inline.} =
Expand Down

0 comments on commit cf42a54

Please sign in to comment.