[tor-bugs] #9330 [Pluggable transport]: Pluggable Transports on windows are killed with ProcessTerminate

Tor Bug Tracker & Wiki blackhole at torproject.org
Fri Oct 25 19:07:11 UTC 2013


#9330: Pluggable Transports on windows are killed with ProcessTerminate
------------------------------+--------------------------------------------
     Reporter:  yawning       |      Owner:  asn
         Type:  defect        |     Status:  new
     Priority:  normal        |  Milestone:
    Component:  Pluggable     |    Version:  Tor: unspecified
  transport                   |   Keywords:  pt, win32, pluggable transport
   Resolution:                |  Parent ID:
Actual Points:                |
       Points:                |
------------------------------+--------------------------------------------

Comment (by GITNE):

 Replying to [ticket:9330 yawning]:
 > The pluggable transport that I am writing needs to do cleanup on
 shutdown (It write files to the pt_state directory, and use a child
 process).

 There multiple ways to accomplish this on Windows:
 * You can implement {{{DllMain()}}} and handle {{{DLL_PROCESS_DETACH}}}
 (don't forget to export it)[[BR]]Since your main process module is
 unloaded last, it is also the last function to be called before actually
 the process' kernel object gets destroyed. Don't get yourself confused,
 this applies to DLLs as well as EXEs.
 * You can listen for a {{{WM_QUIT}}} message with {{{GetMessage()}}} or
 {{{PeakMessage()}}}.[[BR]]This is probably the best approach to your
 problem.

 > The way that tor terminates pluggable transports under Windows currently
 is via ProcessTerminate (common/util.c:tor_terminate_process), which is
 the rough windows equivalent of SIGKILL (Immediate termination, no child
 processes killed, no further code in the application gets executed).

 And, this is not the preferred way to do it on Windows hence Tor's
 problems with sub-processes on Windows. {{{TerminateProcess()}}} does
 neither graceful process shutdown nor does it provide the intended
 semantics for Tor's purpose.

 > In theory Tor is supposed to send SIGINT for a graceful shutdown but it
 doesn't appear to be doing this on Windows (Does it do this at all?
 obfsproxy doesn't appear to install a SIGINT handler to handle graceful
 teardown per the PT spec), and furthermore Microsoft's documentation hints
 at horrible evil happening if SIGINT is actually used
 (http://msdn.microsoft.com/en-us/library/xdkz3x12%28v=vs.110%29.aspx).
 >
 > Some way to properly handle graceful shutdown that works across all
 platforms would be nice.  Apparently the way Real Windows Apps approach
 this problem is with GenerateConsoleCtrlEvent or with PostMessage, neither
 which are portable.

 There is no POSIX approach to this problem on Windows simply because
 Windows does not fully implement POSIX for some better or worse reasons.
 So do not waste time on searching for such a ''cross-platform'' approach
 because you won't find it unless you want to rely on a third party library
 that actually just mimicks POSIX behavoir at best. If you want reliable or
 good Windows support, do it the Windows way (as hard as it sounds).

 > Note: I don't do Windows development as a general rule so I may be
 missing something obvious.

 If so, then my advice is to really listen to Windows developers even then
 when it should mean more work or be a pain in the bu*t.

-- 
Ticket URL: <https://trac.torproject.org/projects/tor/ticket/9330#comment:7>
Tor Bug Tracker & Wiki <https://trac.torproject.org/>
The Tor Project: anonymity online


More information about the tor-bugs mailing list