Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: x/net/context: move to the standard library #13021

Closed
Sajmani opened this issue Oct 22, 2015 · 7 comments
Closed

proposal: x/net/context: move to the standard library #13021

Sajmani opened this issue Oct 22, 2015 · 7 comments

Comments

@Sajmani
Copy link
Contributor

Sajmani commented Oct 22, 2015

The context package provides a standard interface for passing request-scoped values, deadlines, and cancelation information across package boundaries. Examples of request-scoped values include authentication information, golang.org/x/net/trace.Traces, and Dapper-like distributed tracing IDs. Context is widely used: godoc.org lists 1500+ imports. Context is a critical element in RPC systems like Go-kit's Endpoint interface and gRPC Go.

We (@Sajmani and @bradfitz) would like to incorporate Context into standard library packages (see list below). Standard library packages cannot depend on external packages, so we propose moving the context package into the standard library as package "context".

One complication with moving this package is that interfaces that currently mention golang.org/x/net/context.Context will not be satisfied by implementations that use context.Context. For example, gRPC service implementations will fail to compile if we change the Go protocol compiler to use context.Context. We will need to provide some way to manage this transition.

Potential uses of Context in the standard library:

  • Add Context to http.Request to support canceling HTTP requests and passing request-scoped values
  • Add Context to net.Dialer to support canceling Dial
  • Add Context to functions in database/sql and interfaces in database/sql/driver to support canceling database operations and passing request-scoped values
  • Generally, add Context to any function that supports cancelation and may be implemented using RPCs
@Sajmani Sajmani self-assigned this Oct 22, 2015
@Sajmani
Copy link
Contributor Author

Sajmani commented Oct 22, 2015

A related proposal is to remove the Deadline method from the Context interface and so remove its dependence on the "time" package. This would permit the Context interface to be used in packages that cannot depend on "time". Context's deadline support would be implemented using a Context value. Callers would access the deadline with a function in a separate package deadline as deadline.FromContext(context.Context) (time.Time, bool). This is a more invasive change than the original proposal; it is only justified if we can identify packages that should use Context but cannot depend on "time".

@adg
Copy link
Contributor

adg commented Oct 23, 2015

Please write this up as a proposal doc.

@rsc rsc added this to the Proposal milestone Oct 24, 2015
@rsc
Copy link
Contributor

rsc commented Oct 24, 2015

Please write a proposal doc. Be sure to mention

  • the migration problem
  • tradeoffs for what package Context should go into
  • a list of what changes would be made in the standard library to use Context

FWIW I don't see any compelling reason to try to eliminate references to package time from the context API. Even if Context were to go into io, it seems okay to me at first glance to make io depend on time.

Thanks.

@rsc rsc changed the title proposal: move golang.org/x/net/context to the standard library proposal: x/net/context: move to the standard library Oct 24, 2015
@gopherbot
Copy link
Contributor

CL https://golang.org/cl/21810 mentions this issue.

gopherbot pushed a commit that referenced this issue Apr 11, 2016
Updates #13021
Updates #15224

Change-Id: Ia3cd608bb887fcfd8d81b035fa57bd5eb8edf09b
Reviewed-on: https://go-review.googlesource.com/21810
Reviewed-by: Andrew Gerrand <[email protected]>
Run-TryBot: Brad Fitzpatrick <[email protected]>
Reviewed-by: Emmanuel Odeke <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
@gopherbot
Copy link
Contributor

CL https://golang.org/cl/22101 mentions this issue.

gopherbot pushed a commit that referenced this issue Apr 15, 2016
For #12580 (http.Transport tracing/analytics)
Updates #13021

Change-Id: I126e494a7bd872e42c388ecb58499ecbf0f014cc
Reviewed-on: https://go-review.googlesource.com/22101
Run-TryBot: Brad Fitzpatrick <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
Reviewed-by: Mikio Hara <[email protected]>
@gopherbot
Copy link
Contributor

CL https://golang.org/cl/22124 mentions this issue.

gopherbot pushed a commit that referenced this issue Apr 16, 2016
This simply connects the contexts, pushing them down the call stack.
Future CLs will utilize them.

For #12580 (http.Transport tracing/analytics)
Updates #13021

Change-Id: I5b2074d6eb1e87d79a767fc0609c84e7928d1a16
Reviewed-on: https://go-review.googlesource.com/22124
Reviewed-by: Ian Lance Taylor <[email protected]>
Run-TryBot: Brad Fitzpatrick <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
@josharian
Copy link
Contributor

This got done. Closing.

@golang golang locked and limited conversation to collaborators Jul 16, 2017
@rsc rsc unassigned Sajmani Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants