Is net.Conn concurrency-safe?

96 views
Skip to first unread message

sanja...@softwaremotor.com

unread,
Dec 18, 2017, 7:51:26 AM12/18/17
to golang-nuts
In the documentation for https://golang.org/pkg/net/#Conn, it's stated that 

Multiple goroutines may invoke methods on a Conn simultaneously.

My guess is this is not meant to imply that it is necessarily safe to do so. For instance, calls to Set*Deadline may create race conditions between goroutines. However, if this is true it also makes the quoted claim pointlessly self-evident.

Am I missing something or is the documentation somewhat misleading here? You could argue (and it would be perfectly fair) that programmers should be aware of these sorts of obvious concurrency problems, but the misleading nature of the documentation has me questioning whether I can trust it at all.

an...@aubble.com

unread,
Dec 18, 2017, 9:48:09 AM12/18/17
to golang-nuts
Not sure where what is prompting your question, how are the docs misleading? The docs are very clear, net.Conn is concurrency safe.

an...@aubble.com

unread,
Dec 18, 2017, 9:54:27 AM12/18/17
to golang-nuts
Ah I see. You mean its obvious that multiple goroutines may invoke methods on a Conn simultaneously, your question is whether its safe or not, which the docs do not answer.

The docs definitely intend on meaning that it is in fact safe to invoke methods on a Conn simultaneously.

But I agree, the docs could be clarified. I think it would be best to open an issue on GitHub regarding this.
Reply all
Reply to author
Forward
0 new messages