0

I've asked this question more or less before on stackoverflow and believed it to be solved (hence accepted the answer) but it turns out it wasnt solved. :-(

In simple terms, I've written a python script which just outputs text constantly to stdout, thats all it does 24/7. I've linked it to this xinetd file

service myservice
{
    instances = 1
    port = 887
    socket_type = stream
    type = UNLISTED
    wait = no
    user = nobody
    server = /usr/local/bin/myscript.py
    only_from = 127.0.0.1 192.168.1.2
    disable = no
    max_load = 5.0
    nice = 5
    per_source = 1
}

This works fine in as much as when a client connects it starts spewing out text on their console. The problem is when the client disconnects, the process launched stays open, blocking the port. There is only one client allowed (instances = 1) but this can occur when the client reboots while connected.

Previously I thought this was because the python script was ignoring kill signals (which it was) but with this fixed, the same behaviour is observed. To clarify, kill -1 etc is now happily observed by the python script.

I'm assuming this is a xinetd issue and fairly simple to fix ?

Hennes
  • 65,804
  • 7
  • 115
  • 169
Sirex
  • 11,214

2 Answers2

1

Make the server process exit when it detects a disconnection.


Added When the server's OS detects that the TCP connection has been closed, reads to and writes from stdout/stderr will fail with:

IOError: [Errno 104] Connection reset by peer

So make sure your code is not ignoring exceptions when they occur.


However, this (and any other method) will only work when the server knows about the disconnection. Clean reboots usually close all TCP connections, but "pulling the plug" does not.

grawity
  • 501,077
-1

Have you tried to set wait = yes?

According to documentation, that is

wait — Defines whether the service is single-threaded (yes) or multi-threaded (no).