Skip to content

Commit

Permalink
[Backport] Fixes callbacks being dropped on Linux/macOS/BSD.
Browse files Browse the repository at this point in the history
Fixes #15003.

This is a serious bug which occurs when data cannot be read/sent
immediately and there are a bunch of other read/write events
pending. What happens is that the new events are dropped which
results in the case of the reported bug resulted in some data not
being sent (!).
  • Loading branch information
dom96 committed Jul 18, 2020
1 parent 169ca37 commit aa428dd
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/pure/asyncdispatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1228,14 +1228,19 @@ else:
let newLength = max(len(curList), InitCallbackListSize)
var newList = newSeqOfCap[Callback](newLength)

var eventsExtinguished = false
for cb in curList:
if eventsExtinguished:
newList.add(cb)
continue
if not cb(fd):
# Callback wants to be called again.
newList.add(cb)
# This callback has returned with EAGAIN, so we don't need to
# call any other callbacks as they are all waiting for the same event
# on the same fd.
break
# We do need to ensure they are called again though.
eventsExtinguished = true

withData(selector, fd.int, fdData) do:
# Descriptor is still present in the queue.
Expand Down

0 comments on commit aa428dd

Please sign in to comment.