contextualizing-contexts

module
v0.0.0-...-d8e5aec Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2024 License: Apache-2.0

README

This repository contains code samples to demonstrate vagaries around Go's context API.

Structure

  • {grpc,http}-in-series: shows the behavior of a function with manual deadline management juxtaposed with the context's native cancellation mechanisms as implemented respectively through gRPC and HTTP server libraries.

  • {grpc,http}-branch: shows the behavior of the same function from {grpc,http}-in-series run in a separate goroutine from the respective server libraries to connect how the server's dispatch functions handle context lifetime.

  • {grpc,http}-notify: shows the lifetime behaviors of the context from the respective server libraries to establish when lifetime begins and ends in isolation.

  • {grpc,http}-deadline: reveals what deadline the server library attaches to the context (if any).

    http-deadline-synth demonstrates a deadline with the HTTP stack using a homegrown X-MTP-Deadline request header (uses http.TimeFormat values).

    $ curl -H "X-MTP-Deadline: $(LC_ALL=C TZ=GMT date -d 'now + 1 minutes' '+%a, %d %b %Y %T %Z')" localhost:8080
    
  • {grpc,http}-complete: these combine respectively {grpc,http}-{branch,deadline,notify} and http-deadline-synth into one server to show you all of the moving parts of the original quiz.

The server samples serve on localhost:8080:

  • Clients can exercise the HTTP servers with curl:

    $ curl localhost:8080
    
  • Clients can exercise the gRPC servers the gRPC CLI (grpc_cli):

    $ grpc_cli call localhost:8080 proto.Test.Exercise ''
    

Try exercising the gRPC servers with varying values of the grpc_cli's --timeout flag. There is no default timeout/deadline.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL