An interesting mistake with Go's context package
Go&#x27;s context package is great, but also hard to reason about. As developers, we often times like to think that just piping a context through a function chain will take care of all of your timeouts concerns for you.<p>Some fun context gotchas:<p>- Using `req, err := http.NewRequest(...)` to create an http request, and then calling `client.Do(req)` does not do anything with context, you need to use `http.NewRequestWithContext(...)`. [0]<p>- Creating a function that accepts a `ctx context.Context` and then making a blocking call that doesn&#x27;t respect your context will still block for the entirety unless you instrument it yourself.<p>- If a parent context is canceled, all children (derived) contexts will also be canceled. However, only if they are explicitly checking `context.Done()`.<p>- And the worst of all is passing things that decide business logic in your context variables! First, you lose all benefits of go&#x27;s static typing. Second, you will not realize all of the crazy places that a context scoped variable is coming from, have fun debugging that!<p>[0] <a href="https:&#x2F;&#x2F;golang.org&#x2F;pkg&#x2F;net&#x2F;http&#x2F;#NewRequest" rel="nofollow">https:&#x2F;&#x2F;golang.org&#x2F;pkg&#x2F;net&#x2F;http&#x2F;#NewRequest</a>