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

pkg/transport, rafthttp: CancelableTransport #7602

Closed

Conversation

heyitsanthony
Copy link
Contributor

A transport that is tied to a context. Lets the consumer cancel all requests
and dials with a single Cancel.

Related: #7594

if err != nil {
return nil, err
}
return conn, nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why isn't return dialer.DialContext(ctx, "unix", addr) sufficient for line 83-87?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there was some other stuff here, will clean up

func (c *CancelableTransport) Cancel() { c.cancel() }

func (c *CancelableTransport) RoundTrip(req *http.Request) (*http.Response, error) {
if req.Context() != context.Background() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how should we handle the case that req.Context() == context.TODO()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's checking for the default for a request, which is context.Background(). The request would have to explicitly override it with TODO

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the context of the request is overridden with TODO, then that request can't be cancelled even if CancelableTransport.Cancel() is called right? If yes, is that an expected behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's meant to override the default ctx. If the user passes their own ctx into it, this won't override it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it. I think adding a comment about this check will be great.

if ctx.Err() != nil {
return nil, ctx.Err()
}
return tdialer.DialContext(ctx, net, addr)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you know if DialContext() handle cancelled/erred ctx properly? so that you don't have to check the ctx.Err() != nil beforehand.

"net"
"net/http"
"strings"
"time"
)

type CancelableTransport struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we have some sort of test for CancelableTransport?

@gyuho gyuho mentioned this pull request Mar 27, 2017
26 tasks
errc := make(chan error, 1)
go func() {
defer close(errc)
req, reqerr := http.NewRequest("GET", sock, strings.NewReader("abc"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the sock here be prepend with unix:, e.g unix:whatever:123? Or else tr.RoundTrip(req) will never connect to the listener created by NewUnixListener(sock)?

@fanminshi
Copy link
Member

lgtm, thanks!

}

func (c *CancelableTransport) Ctx() context.Context { return c.ctx }
func (c *CancelableTransport) Cancel() { c.cancel() }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add comment?

cancel context.CancelFunc
}

func (c *CancelableTransport) Ctx() context.Context { return c.ctx }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment?

func (c *CancelableTransport) Ctx() context.Context { return c.ctx }
func (c *CancelableTransport) Cancel() { c.cancel() }

func (c *CancelableTransport) RoundTrip(req *http.Request) (*http.Response, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment?

@xiang90
Copy link
Contributor

xiang90 commented Mar 28, 2017

lgtm

A transport that is tied to a context. Lets the consumer cancel all requests
and dials with a single Cancel.
@stale
Copy link

stale bot commented Apr 6, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Apr 6, 2020
@stale stale bot closed this Apr 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

3 participants