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/exp/jsonrpc2: add ConnectionOptions.ConnContext as net/http.Server.ConnContext #62701

Open
maxatome opened this issue Sep 18, 2023 · 1 comment
Labels
Milestone

Comments

@maxatome
Copy link

The context.Context passed to Handler.Handle or Preempter.Preempt is not canceled when the connection is closed. Each async (long-running) handler has to monitor the end of the connection by itself to stop running when this happens.

The goal of this proposal is to mimic net/http.Server.ConnContext and so to allow the user to provide its own context.Context derived from the "server" one.

To be backward compatible, a new ConnContext field can be added to ConnectionOptions as:

// ConnectionOptions holds the options for new connections.
type ConnectionOptions struct {
	…
	// ConnContext optionally specifies a function that modifies
	// the context used for a new connection conn.
	ConnContext func(ctx context.Context, conn *Connection) context.Context
}

This function will then be called in newConnection just after Binder.Bind is called as:

 	options, err := binder.Bind(ctx, c)
 	if err != nil {
 		return nil, err
 	}
+ 	if options.ConnContext != nil {
+ 		ctx = options.ConnContext(ctx, c)
+ 		if ctx == nil {
+ 			panic("ConnContext returned nil")
+ 		}
+ 	}
  	if options.Framer == nil {
@gopherbot gopherbot added this to the Proposal milestone Sep 18, 2023
@gopherbot
Copy link

Change https://go.dev/cl/529175 mentions this issue: jsonrpc2: add jsonrpc2.ConnectionOptions.ConnContext

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Incoming
Development

No branches or pull requests

2 participants