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

Socket activation does not work #1492

Closed
lez opened this Issue Sep 1, 2016 · 6 comments

Comments

3 participants
@lez
Contributor

lez commented Sep 1, 2016

I configured socket activation using this .socket file:

[Socket]
ListenStream=10090

When I connect to port 10090, cherrypy starts up, but throws an error:

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/cherrypy/process/wspbus.py", line 202, in publish
    output.append(listener(*args, **kwargs))
  File "/usr/local/lib/python3.5/dist-packages/cherrypy/_cpserver.py", line 168, in start
    ServerAdapter.start(self)
  File "/usr/local/lib/python3.5/dist-packages/cherrypy/process/servers.py", line 171, in start
    wait_for_free_port(*self.bind_addr)
  File "/usr/local/lib/python3.5/dist-packages/cherrypy/process/servers.py", line 442, in wait_for_free_port
    raise IOError("Port %r not free on %r" % (port, host))
OSError: Port 10090 not free on '0.0.0.0'

When I remove the lines from around server.py:172, the socket activation works fine:

# Start the httpserver in a new thread.
if isinstance(self.bind_addr, tuple):
    wait_for_free_port(*self.bind_addr)

I use the HEAD version of cherrypy, and the following systemd version:

systemd 229
+PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ -LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD -IDN
@webknjaz

This comment has been minimized.

Show comment
Hide comment
@webknjaz

webknjaz Sep 1, 2016

Member

This feature has been submitted lately, but doesn't have test coverage. I didn't verify it works well. See #1458. So let's call @xaiki and ask him to help us :)

Of course, it would be nice to have this feature covered with tests and proved working well. So any help with this is welcome.

It seems those lines lack check similar to this:
https://github.com/xaiki/cherrypy/blob/d168536db5ee59151a68d170a6fd6fc72ceecc14/cherrypy/process/servers.py#L231-L233

if not os.environ.get('LISTEN_PID', None):

Could you please check my assumption and prepare PR?

Member

webknjaz commented Sep 1, 2016

This feature has been submitted lately, but doesn't have test coverage. I didn't verify it works well. See #1458. So let's call @xaiki and ask him to help us :)

Of course, it would be nice to have this feature covered with tests and proved working well. So any help with this is welcome.

It seems those lines lack check similar to this:
https://github.com/xaiki/cherrypy/blob/d168536db5ee59151a68d170a6fd6fc72ceecc14/cherrypy/process/servers.py#L231-L233

if not os.environ.get('LISTEN_PID', None):

Could you please check my assumption and prepare PR?

@webknjaz webknjaz added the bug label Sep 2, 2016

lez pushed a commit to lez/cherrypy that referenced this issue Sep 3, 2016

Laszlo Megyer
Fix systemd socket activation (cherrypy#1492)
when starting up cherrypy via socket activation we
should not wait for the port to become free because
systemd is bound to it.
@lez

This comment has been minimized.

Show comment
Hide comment
@lez

lez Sep 3, 2016

Contributor

You are right that adding a check for LISTEN_PID fixes the issuel. PR submitted.

One thing I'd like to ask @xaiki just out of curiosity is on what configuration did the original socket activation code work? I could not come up with one that makes that code work.

Contributor

lez commented Sep 3, 2016

You are right that adding a check for LISTEN_PID fixes the issuel. PR submitted.

One thing I'd like to ask @xaiki just out of curiosity is on what configuration did the original socket activation code work? I could not come up with one that makes that code work.

@webknjaz

This comment has been minimized.

Show comment
Hide comment
@webknjaz

webknjaz Sep 3, 2016

Member

I guess, he just missed this piece of code, while cutting it off their fork.

Member

webknjaz commented Sep 3, 2016

I guess, he just missed this piece of code, while cutting it off their fork.

@webknjaz webknjaz closed this in 8b540ba Sep 3, 2016

@lez

This comment has been minimized.

Show comment
Hide comment
@lez

lez Sep 3, 2016

Contributor

or maybe newer systemd closes the listening socket right after starting cherrypy.

Contributor

lez commented Sep 3, 2016

or maybe newer systemd closes the listening socket right after starting cherrypy.

@webknjaz

This comment has been minimized.

Show comment
Hide comment
@webknjaz

webknjaz Sep 3, 2016

Member

In this was the case, it wouldn't work

Member

webknjaz commented Sep 3, 2016

In this was the case, it wouldn't work

@xaiki

This comment has been minimized.

Show comment
Hide comment
@xaiki

xaiki Sep 6, 2016

Contributor

sorry was offline for a week, looks we missed that one, thanks @lez

Contributor

xaiki commented Sep 6, 2016

sorry was offline for a week, looks we missed that one, thanks @lez

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment