From: Johannes Sixt Date: Fri, 27 Nov 2009 19:59:25 GMT Subject: Re: [msysGit] [PATCH/RFC 06/11] run-command: add kill_async() and is_async_alive() Message-ID: <200911272059.25934.j6t@kdbg.org> In-Reply-To: <40aa078e0911270804i1a828ea6we1611047d37869f7@mail.gmail.com> On Freitag, 27. November 2009, Erik Faye-Lund wrote: > Do you really think it's better to unconditionally take down the > entire process with an error, instead of having a relatively small > chance of stuff blowing up without any sensible error? I'm not 100% > convinced - but let's hope we'll find a proper fix. "relatively small chance of stuff blowing up"? The docs of TerminateThread: "... the kernel32 state for the thread's process could be inconsistent." That's scary if we are talking about a process that should run for days or weeks without interruption. The reason why we are killing a thread is to prevent keeping lots of connections open (to the same IP address). There are two situations to take care of: 1. We are in a lengthy computation without paying attention to the socket. 2. The client does not send or accept data for a long time. Case 1 could happen if upload-pack is "counting objects" on a large repository. We would need some way to kill upload-pack. Since it is a separate process anyway, we could use TerminateProcess(). Case 2 could be achieved by using setsockopt() with SO_RCVTIMEO and SO_SNDTIMEO and a tiny timeout. But notice that we would set a timeout in one thread while another thread is waiting in ReadFile() or WriteFile(). Would that work? -- Hannes