Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write to pipe log using vmsplice() (Trac #3) #3

Closed
edsiper opened this issue Jan 28, 2014 · 3 comments
Closed

Write to pipe log using vmsplice() (Trac #3) #3

edsiper opened this issue Jan 28, 2014 · 3 comments

Comments

@edsiper
Copy link
Member

edsiper commented Jan 28, 2014

Linux kernel provides a syscall named vmsplice() which allows to write an
iov struct with zero copy to a pipe, we must use vmsplice() instead of
writev() for that procedure.

Migrated from http://bugs.monkey-project.com/ticket/3

{
    "status": "closed", 
    "changetime": "2011-09-06T19:05:21", 
    "description": "Linux kernel provides a syscall named vmsplice() which allows to write an\niov struct with zero copy to a pipe, we must use vmsplice() instead of\nwritev() for that procedure.\n", 
    "reporter": "edsiper", 
    "cc": "", 
    "resolution": "wontfix", 
    "_ts": "1315335921386186", 
    "component": "Logger", 
    "summary": "Write to pipe log using vmsplice()", 
    "priority": "minor", 
    "keywords": "", 
    "version": "", 
    "time": "2010-05-15T12:48:30", 
    "milestone": "Future Release", 
    "owner": "edsiper", 
    "type": "enhancement"
}
@edsiper
Copy link
Member Author

edsiper commented Jan 28, 2014

Trac update at 20100726T17:59:53: charlie_brown commented:

I was skimming through the code and it came to my attention the following commented snippet:

        /* for some reason, vmsplice is not working as expected for us, 
         * maybe we need to fix something here, at the moment
         * we will keep using writev to push the iovec struct to the pipe
         *
         *
         * n = vmsplice(fd, 
         *            (const struct iovec *) mk_io->io, 
         *            mk_io->iov_idx, 
         *            SPLICE_F_GIFT);
         * return n;
         */
  1. vmsplice's man page states that when the SPLICE_F_GIFT flag is present, the memory pointed by each iovec's iov_base MUST be aligned to page boundary:
    ''"Data must also be properly page aligned, both in memory and length."''
    which, if one dumps the iov_base addresses at run-time, they're not.

  2. BUT if we remove SPLICE_F_GIFT, the logger writes to the files with interleaved garbage from the response headers; I haven't checked why.

@edsiper
Copy link
Member Author

edsiper commented Jan 28, 2014

Trac update at 20110227T00:07:34:

  • edsiper changed milestone from "" to "Future Release"
  • edsiper changed priority from "major" to "minor"

@edsiper
Copy link
Member Author

edsiper commented Jan 28, 2014

Trac update at 20110906T19:05:21:

  • davidlohr commented:

This code has been determined to be unapplicable and has already been removed.

  • davidlohr changed resolution from "" to "wontfix"
  • davidlohr changed status from "new" to "closed"

@edsiper edsiper closed this as completed Jan 28, 2014
edsiper added a commit that referenced this issue Jul 7, 2015
This patch implements a new scheduler interface that allows the plugins to
defer the release of some object, the context and requirement of implementation
is based on the following behavior:

 1. A connection is being handled by a plugin (e.g: CGI), the CGI plugin also
    registered it own 'event' into the Event Loop to read incoming data from the
    child process.

 2. Before to receive the response, the client for some reason closes
    the TCP connection.

 3. The Scheduler will trap the 'close event' on the connection and start
    notifying the protocol handler and the plugin associated about this.

 4. The plugin will catch the notification on it stage30_hangup() callback so it
    will release it resources (CGI context, child process,
    close file desriptors, etc).

 5. At this point in the same Event Loop round, it may contain many events notified
    in the array, e.g:

    [0]   TCP connection closed
    [N]   others...
    [16]  Read data from CGI child

    So when we reach the the 'TCP connection closed'[0], we perform a release procedure as
    stated on #3 and #4, but then we reach 'Read data from CGI child'[16] but our event
    context was already released due to 'TCP connection closed'[0]. For hence we face a
    memory corruption.

In order to avoid this kind of situations, the Scheduler and the plugins interface now
provides a new interface to request the Server to perform a 'memory release' of a linked
list of 'struct mk_event' after processing all the events in the round returned by mk_event_wait().

A plugin only requires to be aware of the broken connection stage30_hangup() and register it
event object mk_api->sched_event_free(struct mk_event *x).

Signed-off-by: Eduardo Silva <eduardo@monkey.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant