Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

go 1.8 net/http timeouts


Published on

Go Conference 2017 Spring LT

Published in: Technology
  • Be the first to comment

go 1.8 net/http timeouts

  1. 1. GO1.8 NET/HTTP TIMEOUTS 2017-03-25 Tetsuya Morimoto
  2. 2. ABOUT ME Tetsuya Morimoto twitter: @t2y I like Python, Java and Go! Yahoo Japan Corporation Data & Science Solutions Group Apprentice Infrastructure engineer Mission: OPS → SRE
  3. 3. RECENT WORK Qiita [ ] (SRE) Go 1.8 Graceful Shutdown Python 3/21 3/18 1/27
  4. 4. GO 1.8 FEATURE
  5. 5. MINOR CHANGES Go 1.8 net/http changes from release note “The Server adds configuration options ReadHeaderTimeout and IdleTimeout and documentsWriteTimeout. ”
  6. 6. NOTABLE ARTICLES The complete guide to Go net/http timeouts So you want to expose Go on the Internet Written by @FiloSottile (FilippoValsorda) “ Back when crypto/tls was slow and net/http young, the general wisdom was to always put Go servers behind a reverse proxy like NGINX. That's not necessary anymore! ”
  8. 8. SOCKETTIMEOUTS net.Conn interface SetDeadline (SetReadDeadline/SetWriteDeadline) I/O operation with timeout Let’s Socket Programming! Socket is an API working on transport layer Go TCP Go TCP socket bind listen accept Conn Transport Layer
  9. 9. HTTP SERVERTIMEOUTS Application Layer Go1.8 Go1.7 new! ReadHeaderTimeout These images are quoted from Filippo’s article on
  10. 10. HTTP SERVERTIMEOUTS net/http: no way of manipulating timeouts in Handler #16100 issued at 2016-06-18 (Go 1.6.x) Go 1.8 introduces ReadHeaderTimeout Reset read deadline after reading the request header Application Layer “ Go 1.8 introduces ReadHeaderTimeout, which only covers up to the request headers. However, there's still no clear way to do reads with timeouts from a Handler. ”
  11. 11. HTTP CLIENTTIMEOUTS Application Layer This image is quoted from Filippo’s article on “ Client-side timeouts can be simpler or much more complex, … ”
  12. 12. CONTEXT PACKAGE context is standard way the advantage a request will cancel if parent context would cancel ctx, cancel := context.WithCancel(context.TODO()) timer := time.AfterFunc(5*time.Second, func() { cancel() }) req, err := http.NewRequest("GET",“http://”, nil) if err != nil { log.Fatal(err) } req = req.WithContext(ctx)
  13. 13. SUMMARY Timeouts is important for effective/stable Web service. including against malicious attack (DoS/DDoS) Go 1.8 http.Server is enough stable!