Skip to content
This repository has been archived by the owner on Aug 19, 2022. It is now read-only.

respect the context #2

Closed
marten-seemann opened this issue Nov 24, 2018 · 3 comments
Closed

respect the context #2

marten-seemann opened this issue Nov 24, 2018 · 3 comments
Labels
kind/enhancement A net-new feature or improvement to an existing feature

Comments

@marten-seemann
Copy link
Collaborator

The Go standard library doesn't provide any way to use a Context when handshaking on pre-dialed TCP connection, see golang/go#18482.

@marten-seemann marten-seemann added the kind/enhancement A net-new feature or improvement to an existing feature label Nov 24, 2018
@marten-seemann
Copy link
Collaborator Author

marten-seemann commented Nov 24, 2018

I'm not sure if there's a good solution here.
The two obvious methods rely on modifying state of the underlying net.Conn:

  • closing the connection
  • setting read / write deadlines

Closing the connection is undesirable since the application might want to reuse the connection for something else. Setting deadlines is undesirable because there's no way to read a deadline that's already set on the connection, so we'd have to modify the deadline when the context is canceled.

@marten-seemann
Copy link
Collaborator Author

@Stebalien What do you think about this? It seems like there's nothing we can do because of the fundamental incompatibility of io.Reader and the context.

@Stebalien
Copy link
Member

I'd close the connection. Once we start reading/writing to the connection, there's really no way to recover it without some kind of "cleanup" handshake and some way to signal to the caller that the connection is "clean".

Note: Handling situations like this was one of the goals of the serial-stream multiplexer (in the multistream-2.0 proposal).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/enhancement A net-new feature or improvement to an existing feature
Projects
None yet
Development

No branches or pull requests

2 participants