Thanks so much, I had in fact been using buffered readers and writers, for this test and had removed them to make my example more lean, forgetting that the read and write methods behave differently to those of net.Conn.
My original problem when using the buffered readers and writers is that I had confused the doc for bufio.Writer.Write which states, an error will be returned only if the number of bytes written is not equal to the length of the buffer, with the doc for bufio.Reader.Read believing that bufio.Reader.Read would behave in a similar fashion. In fact It is io.Readfull that behaves in that way. For reference here is a corrected version of the test using buffered readers and writers. https://play.golang.org/p/09uZlxQJX-Y On Friday, March 9, 2018 at 3:56:38 PM UTC, andrey mirtchovski wrote: > > it deadlocks because you're not reading all the data. Read() may > return "up to len(p)", but not necessarily the whole thing. the reader > should loop until it reads all available bytes in your case you know > how many bytes you are going to write beforehand. > > if you do not ignore the first value returned from Read() and Write() > it will become very obvious. > > On Fri, Mar 9, 2018 at 8:44 AM, <pierspo...@gmail.com <javascript:>> > wrote: > > Hi all > > > > I've written a simple program which simply sends a message across a tcp > > connection and back again. > > > > For some reason when I make the buffer larger than a certain size the > > program deadlocks. > > > > When run on the playground with datalen set to 10000 the program > deadlocks > > but with datalen set to 1000 it functions fine. On my local machine it > > deadlocks with datalen set to 1e7 but is fine with datalen set to 1e6. > > > > The program in question is here https://play.golang.org/p/q7QWA4Uz-3H > > > > Please could someone shed some light onto this, I'm literally going nuts > ;) > > > > -- > > You received this message because you are subscribed to the Google > Groups > > "golang-nuts" group. > > To unsubscribe from this group and stop receiving emails from it, send > an > > email to golang-nuts...@googlegroups.com <javascript:>. > > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.