Re: [go-nuts] Potential race condition in prototypical network server code

2017-08-24 Thread Tom Payne
Ah, cool. So graceful shutdown can be achieved by calling Close() on the net.Listener. Nice! Thank you :) Tom On Thursday, August 24, 2017 at 8:20:34 PM UTC+2, Jan Mercl wrote: > > net.Listener has a Close method that will make Accept return an error. > net.Listener.Accept is not equal to

Re: [go-nuts] Potential race condition in prototypical network server code

2017-08-24 Thread Jan Mercl
net.Listener has a Close method that will make Accept return an error. net.Listener.Accept is not equal to accept(2). On Thu, Aug 24, 2017, 20:13 Tom Payne wrote: > Thanks. Looking at the man page for Linux's accept(2) > http://man7.org/linux/man-pages/man2/accept.2.html it

Re: [go-nuts] Potential race condition in prototypical network server code

2017-08-24 Thread Tom Payne
Thanks. Looking at the man page for Linux's accept(2) http://man7.org/linux/man-pages/man2/accept.2.html it seems that l.Accept is unlikely to ever return an error. accept(2) returns an error if either the connection is incorrectly set up somehow, or if a system call is interrupted by a

Re: [go-nuts] Potential race condition in prototypical network server code

2017-08-24 Thread Jan Mercl
The wg.Wait will be executed after l.Accept returns an error. It's purpose is to wait for the completions of all handlers invoked in the go statement that did not finished already. On Thu, Aug 24, 2017, 19:49 Tom Payne wrote: > Awesome, thanks Jan for the fast and clear

Re: [go-nuts] Potential race condition in prototypical network server code

2017-08-24 Thread Tom Payne
Awesome, thanks Jan for the fast and clear response. In fact, the for {} is an infinite loop so wg.Wait() will never be reached and serve() will never terminate. Correct? I guess I over-read how much this prototypical code was representative of a real server loop. Sorry Dave! Tom On

Re: [go-nuts] Potential race condition in prototypical network server code

2017-08-24 Thread Jan Mercl
No, wg.Add cannot "switch" to wg.Wait, they're both in the samr goroutine, the go statement will be always the next one to execute after wg.Add within serve(). On Thu, Aug 24, 2017, 19:29 Tom Payne wrote: > I'm not singling out Dave Cheney here, I'd just like to check my >

[go-nuts] Potential race condition in prototypical network server code

2017-08-24 Thread Tom Payne
I'm not singling out Dave Cheney here, I'd just like to check my understanding of Go's resource handling and concurrency. In this blog post a "prototypical network server" is presented: https://dave.cheney.net/2017/08/20/context-isnt-for-cancellation Code: func serve(l net.Listener) error