unicorn Ruby/Rack server user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: Amir Yalon <amiryal@yxejamir.net>
Cc: unicorn-public@bogomips.org
Subject: Re: Systemd socket inheritance fails with “not a socket file descriptor”
Date: Tue, 8 Mar 2016 03:31:41 +0000	[thread overview]
Message-ID: <20160308033141.GA10218@dcvr.yhbt.net> (raw)
In-Reply-To: <1457392131.48974.542407130.6981D79B@webmail.messagingengine.com>

Amir Yalon <amiryal@yxejamir.net> wrote:
> Starting the systemd service with a configuration based on
> http://bogomips.org/unicorn-public/20150708130821.GA1361@luke.ws.skroutz.gr/
> (also found under examples/ in the source code), it fails, and the
> following is seen in the systemd journal:
> > app/vendor/bundle/ruby/2.0.0/gems/unicorn-5.0.1/lib/unicorn/http_server.rb:780:in `for_fd': not a socket file descriptor (ArgumentError)

> The error, in `for_fd': not a socket file descriptor (ArgumentError),
> occurs when attempting `io = Socket.for_fd(fd.to_i)`.

Curious, that means it's failing at the S_ISSOCK at line 53:


fstat() says it's a valid FD, but not a socket.  Maybe IO.for_fd
can enlighten us as to what you're getting if it's not a socket.

Can you try the following change to http_server.rb to dump out
the stat info of the FD that's failing?

It'll still fail at Socket.for_fd, but IO.for_fd should not fail
since fstat() already succeeded.

--- a/lib/unicorn/http_server.rb
+++ b/lib/unicorn/http_server.rb
@@ -777,6 +777,9 @@ def inherit_listeners!
     # to ease debugging, we will not unset LISTEN_PID and LISTEN_FDS
     inherited.map! do |fd|
+      io = IO.for_fd(fd.to_i)
+      io.autoclose = false
+      $stderr.write("fd=#{fd.inspect} #{io.stat.inspect}\n")
       io = Socket.for_fd(fd.to_i)
       io.autoclose = false
       io = server_cast(io)

Also, can you verify the UNICORN_FD env is NOT set by systemd?
(It should not be)


> Using Ruby version 2.0.0p645.  Should I try using 2.2 or later?

If it's easy, sure; but I just tried with 2.0.0-p645 without
problems; so I would try making the change above and verifying
UNICORN_FD is not set when systemd is being used, first.

Ruby itself could not emulate systemd behavior for testing until
2.3.0, but the actual functionality of unicorn w/ systemd should
not be diminished with a real systemd with older Rubies.

Also, for reference, which version of systemd is this?

I checked the latest systemd.git but didn't notice any changes
which would break the expectations of our sd_listen_fds(3)
function emulation:

	git clone https://github.com/systemd/systemd.git
	cd systemd && git log -p src/libsystemd/sd-daemon/

But maybe I missed something...
Fwiw, I tested on Debian jessie w/ systemd 215-17+deb8u3

  reply	other threads:[~2016-03-08  3:31 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-07 23:08 Systemd socket inheritance fails with “not a socket file descriptor” Amir Yalon
2016-03-08  3:31 ` Eric Wong [this message]
2016-03-08  7:45   ` Amir Yalon
2016-03-08 17:39     ` Eric Wong
2016-03-08 20:32       ` Amir Yalon
2016-03-09  3:51         ` Eric Wong
2016-03-09 13:19           ` Systemd socket inheritance fails with “not a socket file descriptor” [take2] Christos Trochalakis
2016-03-09 14:06           ` Systemd socket inheritance fails with “not a socket file descriptor” Christos Trochalakis
2016-03-10  9:48             ` Amir Yalon
2016-03-12  5:30               ` Eric Wong
2016-03-12 23:19             ` Amir Yalon
2016-03-17  0:27               ` [PATCH] doc: reference --keep-file-descriptors for "bundle exec" Eric Wong
2016-03-17 13:09                 ` Amir Yalon
2016-03-17 16:37                   ` Eric Wong

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:

  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=20160308033141.GA10218@dcvr.yhbt.net \
    --to=e@80x24.org \
    --cc=amiryal@yxejamir.net \
    --cc=unicorn-public@bogomips.org \


* 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


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).