Close#644
This commit also include lots of cleanup related to start up and
shutting down as well as logging. Below is an explanation of how the api
starts up and shuts down. It also covers the error conditions and how
they are handled.
networking/goroutine fixes
* break from TCP Accept() loop when connection closed, which was preventing shutdown to proceed
* make sure that UDP functionality doesn't write to writeSeries channel after it has been closed.
* clearer, more specific shutdown message
in particular:
* self.writers allows us to make sure things writing to writeSeries are done
(they do blocking calls to handleMessage()) whether udp or tcp
* self.connClosed lets us break from the Accept() loop,
see http://zhen.org/blog/graceful-shutdown-of-go-net-dot-listeners/ (quit channel)
* shutdown channel is now allCommitted
things can get a little complicated, so here's a little schematic of how the functions and
their logic relate:
indent for a call out or important code within. everything shown as one nested tree
server.go
go ListenAndServe
go committer
reads from self.writeSeries until closed, then writes to self.allCommitted
Serve
for {
Accept, breaks if err + connClosed
self.writers.Add()
go handleClient
for {
handleMessage
reads until err and writes to self.writeSeries until read failed
reads until EOF, ignores other handleMessage errors
}
conn.Close()
self.writers.Done()
}
self.writers.Wait()
close(self.writeSeries)
Close()
close(self.connClosed)
self.conn.Close()
wants confirmation on allCommitted channel; [timeout] returns within 5s