unicorn Ruby/Rack server user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Patrik Wenger <paddor@gmail.com>
To: unicorn list <mongrel-unicorn@rubyforge.org>
Subject: Re: Background jobs with #fork
Date: Fri, 13 Apr 2012 00:41:03 +0200	[thread overview]
Message-ID: <EA11A18D-57EC-4B56-8F24-9943EDCC9E66@gmail.com> (raw)
In-Reply-To: <20120412203956.GA8980@dcvr.yhbt.net>

Thanks for the answers.

> So you're only calling fork and not exec (or system/popen, right?)  It
> may be the case that the client socket is kept alive in the background
> process.

Yes, I'm only calling Kernel#fork. @Eric, your guess makes sense to me.

> The client socket has the close-on-exec flag (FD_CLOEXEC) set, but
> there's no close-on-fork flag, so you might have to find + close it
> yourself.  Here's is a nasty workaround for the child process:
> 
>  ObjectSpace.each_object(Kgio::Socket) do |io|
>    io.close unless io.closed?
>  end

Isn't there another way to retrieve the right socket?

Here some additional info that might bring some clarification.

Another action in the same controller which does about the same regarding the background job works (check.run!).
The only differences I see are:

1) it's called via AJAX
2) the response is nothing (render :nothing => true) instead of a redirect (redirect_to checks_path)

I reckon the second difference kind of confirms Eric's guess, as the client socket probably isn't considered anymore with render :nothing => true.

> However, nginx can still forward subsequent requests to the same unicorn
> (even the same unicorn worker), because as far as the unicorn worker is
> concerned (but not the OS), it's done with the original request.  It's
> just the original request (perhaps the original client) is stuck
> waiting for the background process to finish.
> 
> I can probably writeup a better explanation (perhaps on the usp.ruby
> (Unix Systems Programming for Ruby mailing list) if this doesn't make
> sense.

Yeah I don't really understand this part. The "hanging" Unicorn worker can read another request because the client socket wasn't closed because it's still open in the child process? I would appreciate a better explanation, thank you.
_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying

  parent reply	other threads:[~2012-04-12 22:41 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-12 17:36 Background jobs with #fork paddor
2012-04-12 20:39 ` Eric Wong
2012-04-12 21:15   ` Hongli Lai
2012-04-12 22:10     ` Eric Wong
2012-04-12 22:41   ` Patrik Wenger [this message]
2012-04-12 23:04     ` Eric Wong
2012-04-13  1:04       ` Patrik Wenger
2012-04-13  2:10         ` Eric Wong
2012-04-13 12:11           ` paddor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://yhbt.net/unicorn/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=EA11A18D-57EC-4B56-8F24-9943EDCC9E66@gmail.com \
    --to=paddor@gmail.com \
    --cc=mongrel-unicorn@rubyforge.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhbt.net/unicorn.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).