Giter Club home page Giter Club logo

Comments (4)

0x804d8000 avatar 0x804d8000 commented on May 5, 2024

You oversimplified the code.

Line 176 starts a fiber to run OnReadable asynchronously. This is done to parallelize handling of I/O events. However, this also introduces a side effect that read_events_ can be increased concurrently, after OnReadable draining the read buffer, but before Line 222 is reached.

from flare.

npuichigo avatar npuichigo commented on May 5, 2024

Since a fiber is created and detached after increasing read_events_ from 0 to 1 and L176 is the only line to increase read_events_, could u point out which line may cause concurrent increase of read_events_? Do u mean OnReadable in a fiber may also start parallel invocation to this function?

from flare.

0x804d8000 avatar 0x804d8000 commented on May 5, 2024

Note that epoll event can be triggered any time soon after the fd is drained (edge triggered), even before OnReadable has an opportunity to return.

IOW, there is a time window between returning EAGAIN from syscall read (inside OnReadable), and decrementing read_events_. If new data arrived in this time window, without checking event count we may lose the notification.

Consider this:

F1: Received EPOLLIN, starts F2 to handle it,
F2: Done reading data, is either calling user’s callback or about to return, and got paused (due to whatever reason, e.g., interrupted by system),
F1: Another EPOLLIN comes, now either:

  • We start a new fiber, which would complicate thing a lot, as now the data stream is concurrently handled by two fiber, each with a part of the data (think about what to do if they both contain a portion of a large packet), or
  • We’d miss the notification as OnReadable is about to return, and no one else would read the data.

Yes you’re right the only place that can increment the event count is L176, but it’s exactly that line that helps us to avoid missing the notification.

from flare.

npuichigo avatar npuichigo commented on May 5, 2024

@0x804d8000 Thanks for your detailed explanation. Learn a lot after reading the implementations.

from flare.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.