go 1.8 net/http timeouts

>100 Views

March 27, 17

スライド概要

Go Conference 2017 Spring LT
https://gocon.connpass.com/event/52441/

profile-image

2023年10月からSpeaker Deckに移行しました。最新情報はこちらをご覧ください。 https://speakerdeck.com/lycorptech_jp

シェア

またはPlayer版

埋め込む »CMSなどでJSが使えない場合

(ダウンロード不可)

関連スライド

各ページのテキスト
1.

GO1.8 NET/HTTP TIMEOUTS 2017-03-25 Tetsuya Morimoto

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.

RECENT WORK Qiita [຋༁]αΠτ৴པੑΤϯδχΞϦϯά(SRE)ͱ͸Կ͔ʁ 1/27 Go 1.8 ͷ Graceful Shutdown ͷৼΔ෣͍Λௐ΂ͯΈͨ 3/18 ल࿨γεςϜ 3/21 ϑϦʔϥΠϒϥϦͰֶͿ‫ػ‬ցֶशೖ໳ ෇࿥ࢿྉ ‫ߏڥ؀‬ங΍Python ೖ໳Λࣥච

4.

GO 1.8 FEATURE

5.

MINOR CHANGES Go 1.8 net/http changes from release note “ The Server adds configuration options ReadHeaderTimeout and IdleTimeout and documents WriteTimeout. ”

6.

NOTABLE ARTICLES https://blog.cloudflare.com/ The complete guide to Go net/http timeouts So you want to expose Go on the Internet Written by @FiloSottile (Filippo Valsorda) “ 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! ”

7.

STUDY TIMEOUTS

8.

SOCKET TIMEOUTS Transport Layer net.Conn interface SetDeadline (SetReadDeadline/SetWriteDeadline) I/O operation with timeout Let’s Socket Programming! ɾsocket Socket is an API working on transport layer ɾbind GoͰͨͨ͘TCPιέοτʢલฤʣ ɾlisten ɾaccept GoͰͨͨ͘TCPιέοτʢ‫ޙ‬ฤʣ Conn

9.

HTTP SERVER TIMEOUTS Application Layer Go1.7 Go1.8 ReadHeaderTimeout new! These images are quoted from Filippo’s article on https://blog.cloudflare.com

10.

HTTP SERVER TIMEOUTS Application Layer 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 “ 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.

HTTP CLIENT TIMEOUTS Application Layer “ Client-side timeouts can be simpler or much more complex, … ” This image is quoted from Filippo’s article on https://blog.cloudflare.com

12.
[beta]
CONTEXT PACKAGE
context is standard way

ctx, cancel := context.WithCancel(context.TODO())

the advantage

timer := time.AfterFunc(5*time.Second, func() {

a request will cancel if
parent context would
cancel

cancel()
})
req, err := http.NewRequest("GET", “http://
example.com”, nil)
if err != nil {
log.Fatal(err)
}
req = req.WithContext(ctx)

13.

SUMMARY Timeouts is important for effective/stable Web service. including against malicious attack (DoS/DDoS) Go 1.8 http.Server is enough stable!