GopherCon 2018 - Advanced Networking

conference, golang, gophercon2018, notes

These are some notes from my experiences at the GopherCon 2018. I don’t expect these will be laid out in any particularly useful way; I am mostly taking them so I can remember some of the bits I found most useful in the future.


The Problem

  • Usually try to use the higher-level abstractions unless you can’t

  • Most of the low-level net package is blocking/sync

  • Event loops

    • worker threads pop from event queue until a block would happen
    • notify kernel to notify instead of blocking
    • then work on other things and come back when the blocking bit was ready
  • Advantages of go

    • goroutines
    • (see scheduler notes from earlier)

The net Package

  • net.Conn interface handles the accepting connections

  • net.Listener interface is the server interface

    • especially Accept() (Conn, error), which blocks until a connection is ready
    • so need to Accept() in a loop
  • io.Copy is useful for piping data

  • Remember to set read timeouts

  • Defer conn.Close in the read loop

  • Make sure to know how a goroutine will end so you don’t leak it

  • io.Copy interface upgrades!!

Parsing TLS

  • cryptobyte parser

  • MultiReader!!!! (chain readers)

  • tls.Conn is a net.Conn wrapper!

  • mkcert!! (tool for local certificates)