In a library I have a `func(context.Context, net.Conn)' (more or less,
https://godoc.org/mellium.im/xmpp#NewSession). The context is used
throughout the function to eg. break out of loops, gets passed into
other functions, etc. and the conn is read from. If the user creates and
passes in a context with a deadline and also sets a deadline on the
conn, should I also cancel reads/writes from the conn when the context
is expired, or allow the user the maximum flexibility of setting their
own deadline on both?
I've asked this elsewhere (and am copying it here to reach a wider
audience) and the responses I've gotten seem to fall into:
- The user might have set a deadline on the conn already and overriding
it defies user expectations, and
- The user expects that when the context is canceled the function stops
blocking, so you have to cancel any reads/writes on the conn too
otherwise the function could keep blocking, defying user expectation
I've gone back and forth a couple of times on how I'd expect this to
behave and I couldn't find any obvious examples in the standard
library that would suggest there's a convention so I'd love to get
other opinions.
—Sam
--
Sam Whited