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

net: clarify net.Conn concurrency requirement #27203

Open
FiloSottile opened this Issue Aug 24, 2018 · 7 comments

Comments

Projects
None yet
5 participants
@FiloSottile
Member

FiloSottile commented Aug 24, 2018

From the net.Conn docs:

Multiple goroutines may invoke methods on a Conn simultaneously.

I'm not sure if this should be interpreted as different methods can be called concurrently, or as the same method can be called concurrently.

I suspect, judging from x/net/nettest's ConcurrentMethods and from most implementations, that it's the former. If so, should we change the docs to include "may invoke distinct methods"?

@FiloSottile FiloSottile added this to the Go1.12 milestone Aug 24, 2018

@ianlancetaylor

This comment has been minimized.

Contributor

ianlancetaylor commented Aug 24, 2018

It's the former: any methods may be called concurrently. But changing the docs to say distinct methods would suggest that you could not call the same method concurrently--e.g., two concurrent calls to Write.

Personally I think the current text is clear but I'm open to counter arguments.

@FiloSottile

This comment has been minimized.

Member

FiloSottile commented Aug 24, 2018

Calling the same method concurrently however is not part of the interface contract. Implementations might allow it, but don't have to. With the current text, it's not clear to me if a net.Conn implementation that breaks for concurrent calls to Read is correct.

@ianlancetaylor

This comment has been minimized.

Contributor

ianlancetaylor commented Aug 24, 2018

I don't understand. The text is, as you say, "Multiple goroutines may invoke methods on a Conn simultaneously." To me that clearly states that multiple goroutines may invoke the Read method simultaneously. Are you saying that that does not work?

@FiloSottile

This comment has been minimized.

Member

FiloSottile commented Aug 25, 2018

Ah, I interpreted your first message the other way around.

That seems more strict than what I've seen implemented in practice, but I'm willing to believe it.

x/net/nettest's ConcurrentMethods should test for it then, though, because it looks like it only tests concurrent calls of distinct methods.

@bradfitz

This comment has been minimized.

Member

bradfitz commented Aug 25, 2018

Also, some implementations may promise more: e.g. UDPConn permitting concurrent Write calls.

@networkimprov

This comment has been minimized.

networkimprov commented Aug 25, 2018

Doesn't TCPConn allow simultaneous Write() to a single net.Conn? The docs certainly imply that.

I make TCPConn.Write calls from one goroutine while another does io.Copy (invoking sendfile()), and haven't seen any errors that indicated "connection in use".

Pls do test this formally if possible :-)

@gopherbot add Testing

@FiloSottile

This comment has been minimized.

Member

FiloSottile commented Aug 26, 2018

@bradfitz I'm confused again, AFAICT @ianlancetaylor is saying that all net.Conn implementations must permit concurrent Write calls, so it wouldn't be promising more.

I'll argue that we should make the docs more explicit after all.

@gopherbot gopherbot added the Testing label Aug 26, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment