Edgewall Software
Modify

Ticket #9467 (closed defect: fixed)

Opened 20 months ago

Last modified 13 months ago

Can't kill tracd with CTRL-C (or SIGTERM)

Reported by: davidbarnett2@… Owned by: jomae
Priority: normal Milestone: 0.12.2
Component: web frontend/tracd Version: 0.12
Severity: normal Keywords: needinfo
Cc: fcorreia@…
Release Notes:
API Changes:

Description

If I start up tracd like this:

tracd /path/to/project

and then hit it with the browser, I can't kill the process either by pressing CTRL-C or with kill -15 THE_PID. I can kill the tracd process normally if I do it before the server handles any requests.

Attachments

Change History

comment:1 Changed 20 months ago by cboos

  • Keywords needinfo added

At first this sounded familiar, as I thought I had experienced something similar on Windows recently. But I tested again and now it seems to work as expected.

I just tested on Linux (2.6.27-11-server x86_64 GNU/Linux lenny/sid) and interrupting tracd with a CTRL-C or kill -TERM works, with either plain tracd, or -r, or -d (well, obviously not CTRL-C in the latter case). This behavior is also highly dependent on your terminal settings (stty -a?)

comment:2 Changed 18 months ago by anonymous

I confirm - Ctrl+C can't kill Trac 0.12 after default installation of openSUSE+Yakuake console.

comment:3 Changed 17 months ago by derek@…

... same problem on Centos 5.

comment:4 Changed 17 months ago by roy@…

I'm seeing the same on my Ubuntu box (2.6.32.16-linode28 #1 SMP Sun Jul 25 21:32:42 UTC 2010 i686 GNU/Linux), python 2.6.5, mysql 5.1 backend.

This smells like the kind of behavior you get if you've spawned a thread and are waiting for it to exit.

comment:5 Changed 17 months ago by roy@…

Just to add some details, if I strace the tracd process, here's what I see when I Control-C it. The string of select() calls are the idle behavior before I hit Control-C.

[pid  8062] select(4, [3], [], [], {0, 500000}) = 0 (Timeout)
[pid  8062] select(4, [3], [], [], {0, 500000}) = 0 (Timeout)
[pid  8062] select(4, [3], [], [], {0, 500000}) = 0 (Timeout)
[pid  8062] select(4, [3], [], [], {0, 500000}) = 0 (Timeout)
[pid  8062] select(4, [3], [], [], {0, 500000}) = 0 (Timeout)
[pid  8062] select(4, [3], [], [], {0, 500000}) = 0 (Timeout)
[pid  8062] select(4, [3], [], [], {0, 500000}) = 0 (Timeout)
[pid  8062] select(4, [3], [], [], {0, 500000}) = 0 (Timeout)
[pid  8062] select(4, [3], [], [], {0, 500000}) = 0 (Timeout)
[pid  8062] select(4, [3], [], [], {0, 500000}) = 0 (Timeout)
[pid  8062] select(4, [3], [], [], {0, 500000}) = 0 (Timeout)
[pid  8062] select(4, [3], [], [], {0, 500000}) = 0 (Timeout)
[pid  8062] select(4, [3], [], [], {0, 500000}) = 0 (Timeout)
[pid  8062] select(4, [3], [], [], {0, 500000}) = 0 (Timeout)
[pid  8062] select(4, [3], [], [], {0, 500000}) = ? ERESTARTNOHAND (To be restarted)
[pid  8062] --- SIGINT (Interrupt) @ 0 (0) ---
[pid  8062] rt_sigaction(SIGINT, {0x810fde0, [], 0}, {0x810fde0, [], 0}, 8) = 0
[pid  8062] sigreturn()                 = ? (mask now [])
[pid  8062] futex(0x923e398, FUTEX_WAIT_PRIVATE, 0, NULL

comment:6 Changed 13 months ago by jaroslav.benkovsky@…

I have the same problem on Ubuntu 10.04, tracd is run gnome-terminal through ssh with

$ ssh server.example.com
...
$ su - www-data -c "tracd --port 8000 /var/trac"

The tracd process ignores ^C, ^Z, sigterm and sigint (sent as root, of course). Annoying

Last edited 13 months ago by cboos (previous) (diff)

comment:7 Changed 13 months ago by fcorreia@…

  • Cc fcorreia@… added

comment:8 follow-up: Changed 13 months ago by jomae

I have the same issue with 0.12-stable r10430. CTRL-C cannot stops tracd, however kill -TERM works.

I tested with the following environments and the same issue happens.

  • python 2.4.6 (Debian 5.0)
  • python 2.5.4 and python 2.6.4 (Ubuntu 9.10)
  • python 2.6.6 (Windows XP sp3)

In sending CTRL-C, I think that tracd waits the termination of worker threads TracHTTPServer generates as a non-daemon thread.

In kill -TERM, SIGTERM just kills the tracd process because tracd don't handle SIGTERM.

The worker thread should become a daemon thread.

  • trac/web/standalone.py

    diff --git a/trac/web/standalone.py b/trac/web/standalone.py
    index 9e85c74..0d9d57c 100755
    a b class TracEnvironMiddleware(object): 
    9090 
    9191 
    9292class TracHTTPServer(ThreadingMixIn, WSGIServer): 
     93    daemon_threads = True 
    9394 
    9495    def __init__(self, server_address, application, env_parent_dir, env_paths, 
    9596                 use_http_11=False): 

comment:9 follow-up: Changed 13 months ago by cboos

Are you sure about daemon_threads? 16.2.1. Thread Objects talks about the daemon property.

Besides, how are you starting tracd? When I do simply tracd -p 9001 test-env/, I can interrupt it by ^C without doing anything special (Python 2.5 or 2.7.1, on Linux 2.6.27-11-server x86_64 GNU/Linux).

^C is mapped to intr for you, right? (check with stty -a).

comment:10 in reply to: ↑ 9 Changed 13 months ago by cboos

Replying to cboos:

Are you sure about daemon_threads? 16.2.1. Thread Objects talks about the daemon property.

Sorry, just looked closer. That was for Thread objects, and we're in a SocketServer (20.17).

comment:11 in reply to: ↑ 8 ; follow-up: Changed 13 months ago by rblank

Replying to jomae:

The worker thread should become a daemon thread.

IIRC this could have a negative effect on the reload functionality.

comment:12 in reply to: ↑ 11 ; follow-up: Changed 13 months ago by cboos

Replying to rblank:

Replying to jomae:

The worker thread should become a daemon thread.

IIRC this could have a negative effect on the reload functionality.

That was #7049, and the trouble was with --daemon option which a different thing (the process is set up as daemon process).

Now I was able to reproduce the original issue: if there are many threads or long running threads, I indeed can't interrupt tracd right away.
The patch proposed in comment:8 fixes that. Well done, Jun!

Just to be sure, I also verified that the patch doesn't affect the -r behavior.

comment:13 in reply to: ↑ 12 Changed 13 months ago by jomae

  • Milestone set to 0.12.2
  • Resolution set to fixed
  • Status changed from new to closed

Replying to cboos:

Just to be sure, I also verified that the patch doesn't affect the -r behavior.

Thanks, Christian!

Committed in [10436].

comment:14 Changed 13 months ago by rblank

  • Owner set to jomae
View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
to The owner will be changed from jomae. Next status will be 'closed'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.